Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

RemoteEvent:FireClient() Player Object always returns nil?

Asked by 4 years ago

I'm making an event that the server sends to the client when an Administrator joins, it runs

sgui:SetCore("SendNotification",{
 all the notification stuff goes in here
}

But when testing, every time on the Client side, Player is returning nill

Server:

local remote = game.ReplicatedStorage:WaitForChild("Remote").BROADCAST_ADMIN_JOIN

function fireIfAdmin(tbl, plr)
    for i,v in pairs(tbl) do
        if plr.Name == v then
            remote:FireClient(plr)
        end
    end
end

function checkAdmin(plr)
    local tier4 = {"resupero"}
    local trainer = {"AtomicMoosh", "249Grimawesome"}
    local developer = {"Skychiild"}
    local commander = {"XxExtrapokemonXx"}
    local captain = {"Zakekski_YT"}
    local queen = {"SinCityCello"}

    fireIfAdmin(tier4,plr)
    fireIfAdmin(trainer,plr)
    fireIfAdmin(developer,plr)
    fireIfAdmin(commander,plr)
    fireIfAdmin(captain,plr)
    fireIfAdmin(queen,plr)

end

game.Players.PlayerAdded:Connect(function(plr)
    checkAdmin(plr)
end)

Client:

local remote = game.ReplicatedStorage:WaitForChild("Remote").BROADCAST_ADMIN_JOIN

remote.OnClientEvent:Connect(function(plr)
    print(plr.Name)
end)

Did I make an error somewhere in the server script?

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

There's a better way to go about this. Have a table with all your admin's names.

local Admins = {['PlayerName'] = true,} --Put all admin names here in this format

To check if a player is an admin when they join, then you can simply do

game.Players.PlayerAdded:Connect(function(Player)
    if Admins[Player.Name] then
        --Fire your client event here with the actual Player object as the argument
    end
end

Also, when calling InvokeClient, you must specify to which player you are calling it to, which means it needs two argument inputs if the recieving OnClientInvoke has an argument. In your case, it's plr, which is equal to nothing, since you're using InvokeClient and specifying which player you're sending it to, but not actually giving the 2nd argument a value. To fix that you could just put in plr twice for the arguments.

Although the method above is a lot easier.

Hope this helps.

0
Passing it twice worked! Thank you! Skychiild 4 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I dont know much about lua on roblox etc but i think you have to do the client script after the player loads not before, i dont remember exactly how to do it but a little searching should do

Answer this question