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

Why is my Remote Event reading "Player" as "nil"?

Asked by 3 years ago

I have this In Pairs loop inside a script located on Workspace:

for i,Player in pairs(game.Players:GetPlayers()) do 
    --A bunch of code that isn't relevant to my problem
end

Inside the loop there's this line that refers a Remote Event that when fired should play music Client-Side:

game.ReplicatedStorage.PlayGameMusic:FireClient(Player)

This is the LocalScript on StarterGui that detects when the event is fired:

game.ReplicatedStorage.PlayGameMusic.OnClientEvent:Connect(function(Player)
    local ScreenGui = Player.PlayerGui:WaitForChild("ScreenGui")

    ScreenGui.Music:Play()
end)

But when testing the script In-Game, this shows up in the Output:

Players.Mordevifer.PlayerGui.RemoteFunctionReader:2: attempt to index nil with 'PlayerGui'

I really don't know why is the server sending nil, there's not a red line under Player, so that must mean that the code is in fact inside the loop, but is the problem originating on the loop or the script, my mind is blank right now so I would appreciate someone could help me in this (probably) dumb problem I'm having at the moment.

1 answer

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

when you do fireclient the first parameter is who (which player) you are sending it to. because you are doing fireclient, you can get the player by using localplayer instead.

Ad

Answer this question