For some reason this event wont trigger?


#1

Server

RegisterNetEvent("robbery")
AddEventHandler("robbery", function()
	TriggerClientEvent("chatMessage", -1, "ROBBERY", {255,255,255}, "Paleto Bank is being robbed!")
	TriggerClientEvent("robberyMoney")
end)

Client

RegisterNetEvent("robberyMoney")
AddEventHandler("robberyMoney", function()
	TriggerEvent("chatMessage", "ROBBERY", {255, 255, 255}, "You will recieve your money in 30 seconds.")
	Citizen.Wait(3000)
	cash = cash + 300
end)

The message for TriggerClientEvent("chatMessage", -1, "ROBBERY", {255,255,255}, "Paleto Bank is being robbed!") works but the client event “robberyMoney” is not being triggered. I am not sure why.


#2

You never selected a client target :wink:


#3

The trigger client event doesn’t have a number specifying what player it will trigger on. If you want it to trigger on all, you need to put -1.

TriggerClientEvent('EventName', PlayerID, Arg1, Arg2, Etc...)

Edit: @Vespura ninja.


#4

Thank you, also do you know if there is a way to stop someone from spamming my code:
(There is a blip [thanks @xander1998] and when you go over it if you press E it makes a server message saying there is a bank robbery.) Is there a way to stop someone from spamming it?

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)

        for k in pairs(table) do

            local plyCoords = GetEntityCoords(GetPlayerPed(-1), false)
            local dist = Vdist(plyCoords.x, plyCoords.y, plyCoords.z, table[k].x, table[k].y, table[k].z)

            if dist <= 1.2 then
				DrawText3("Press E To Start A Bank Robbery")
				if IsControlJustPressed(1,51) then
					TriggerServerEvent("robbery")
					TriggerEvent("robberyMoney")
				end
            end
        end
    end
end)

#5

Have a variable on the serverside that is like… local isRobberyActive = false. Then when the event is triggered, check if it is true or false, if it is false, run the event and set it to true.

Or you can use this if they press it too many times :wink:


#6

This helped a lot, but how would I make it true for a certain amount of time?

EDIT: Figured it out, thanks a lot @Briglair