Jump to content

Trigger client event doesn't work


Recommended Posts

I have this snippet of code:

-- Process all the players 
function language_onResourceStart() 
    for index, player in ipairs(getElementsByType("player")) do 
        -- If the player is not logged in, then show language window 
        if isGuestAccount(getPlayerAccount(player)) then 
            triggerClientEvent(player, "language_showWindow", player) 
        end 
    end 
end 
addEventHandler("onResourceStart", root, language_onResourceStart) 
-- Called when a new player joins 
function language_onPlayerJoin() 
    -- Check player account 
    if isGuestAccount(getPlayerAccount(source)) then 
        triggerClientEvent(source, "language_showWindow", source) 
    end 
end 
addEventHandler("onPlayerJoin", root, language_onPlayerJoin) 

The problem is: when a player joins, the function language_onPlayerJoin successfully triggers the client event language_showWindow, but when the resource is started, with the function language_onResourceStart the event is instead not triggered (when it should trigger the event for each client). What is happening with this code? I tried to check if the for loop gets executed, and it does. It also finds the correct players, so the local variable player just seems to be correct. I just don't know what's wrong.

Any help appreciated, thanks.

Link to comment

You should attach the event onResourceStart to resourceRoot.

Your problem is that the server side start BEFORE the client side, the solution is make trigger from the client when it ready to the server side and then trigger again to the client, which mean you won't need onPlayerJoin nor onResourceStart.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...