[SOLVED] Rewriting bank robbing script and having a big issue

So I’ve made a TriggerClientEvent and TriggerServerEvent to handle if they have the item or not and if they do they start hacking but its triggering to everyone on the server and they all start hacking together, how can i limit this to the person that pressed E?

Cheers for any help! :slight_smile:

Client:

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		local playerPed = PlayerPedId()
		local coords = GetEntityCoords(playerPed)

		if GetDistanceBetweenCoords(coords, 261.87, 223.13, 106.28, true) < 0.5 then
			if not IsHackingDoor and not IsDoorHacked then
				ESX.ShowHelpNotification('Press ~INPUT_CONTEXT~ to hack the door!')
			end
			if IsControlJustReleased(0, Keys['E']) and not IsHackingDoor then
				TriggerServerEvent('bankrob:HasGotRaspDoor')
			end
		end
	end
end)

And client trigger:

RegisterNetEvent('bankrob:HasGotRaspDoor')
AddEventHandler('bankrob:HasGotRaspDoor', function(GotRaspDoor)
	local playerPed = PlayerPedId()

		ESX.ShowNotification("hacking started")
		TaskGoStraightToCoord(playerPed, 261.56, 223.26, 106.287, 1.0, -1, 251.41, 0.0)
		IsBlocked = true
		Citizen.Wait(2500)
		TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_STAND_MOBILE', 0, true)
		Citizen.Wait(1000)
		TriggerEvent("mhacking:show")
		TriggerEvent("mhacking:start",7,25,hacking)
		IsHackingDoor = true
end)

Server:

RegisterServerEvent('bankrob:HasGotRaspDoor')
AddEventHandler('bankrob:HasGotRaspDoor', function()
local source = source
local xPlayer = ESX.GetPlayerFromId(source)
local raspberrypi = xPlayer.getInventoryItem('raspberrypi')
local xPlayers = ESX.GetPlayers()

    local cops = 0
    for i=1, #xPlayers, 1 do
     local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
     if xPlayer.job.name == 'police' then
            cops = cops + 1
        end
    end
    if xPlayer.getInventoryItem('raspberrypi').count <= 0 then
        TriggerClientEvent('esx:showNotification', source, '~h~~r~You don\'t have the correct equipment.')
    elseif (cops < Config.NumberOfCopsRequired)then
        TriggerClientEvent('esx:showNotification', source, '~h~~r~Not enough cops in town.')
    elseif (cops >= Config.NumberOfCopsRequired)then
        if xPlayer.getInventoryItem('raspberrypi').count >= 1 then
            TriggerClientEvent('bankrob:HasGotRaspDoor', -1, GotRaspDoor)
        end
    end
end)

changed

TriggerClientEvent('bankrob:HasGotRaspDoor', -1, GotRaspDoor)

to

TriggerClientEvent('bankrob:HasGotRaspDoor', source, GotRaspDoor)

and it works how it should now!