Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Output saying that argument is missing or nil?

This is for a leaderboard that shows the player's names in a gui. Also, am I using the right table globals to insert the player name there?

-- server script
game.Players.PlayerAdded:Connect(function(player)
	game.ReplicatedStorage:WaitForChild("LeaderboardEvents"):WaitForChild("RemoteEvent"):FireClient() 
end)
--localscript
local players = {}
game.ReplicatedStorage.LeaderboardEvents.RemoteEvent.OnClientEvent:Connect(function(player)
	table.insert(players,1,player.Name)
	script.Parent.Text = players[1] or ""
end)

Any help is welcome.

1 answer

✓ Accepted answer

The issue is with the FireClient. FireClient's first parameter is the playerInstance to fire it for. If you want to fire it for the player who joined, make it:

-- server script
game.Players.PlayerAdded:Connect(function(player)
    game.ReplicatedStorage:WaitForChild("LeaderboardEvents"):WaitForChild("RemoteEvent"):FireClient(player) 
end)

Then, you can pass any other stuff through that you need after player. When listening to it on the client, the first parameter received is not the player. So for example:

-- server script
game.Players.PlayerAdded:Connect(function(player)
    game.ReplicatedStorage:WaitForChild("LeaderboardEvents"):WaitForChild("RemoteEvent"):FireClient(player, "StringParam1") 
end)

--localscript
local players = {}
game.ReplicatedStorage.LeaderboardEvents.RemoteEvent.OnClientEvent:Connect(function(param1)
    print(param1); -- "StringParam1"
    table.insert(players,1,player.Name)
    script.Parent.Text = players[1] or ""
end)

This is because LocalPlayer can be used in LocalScripts, but not on ServerScripts. Learn more here.

EDIT: Added developer docs link.

1 comment

0

Okay, I just got a problem with how to send the player name through the parameter, but I actually figured it out. Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.