I am making a minigame type game and when a round ends, a Gui goes on everyone's screens that tells them who won. Well, my core game loop isn't working because my Gui function keeps erroring.
Here is my error message.
20:39:10.170 - Workspace.Editing:110: attempt to index local 'plr' (a nil value)
Why am I getting this? I can't find a workaround or solution for it.
function winnerGui() local plr = game.Players.LocalPlayer local plrGui = plr:WaitForChild("PlayerGui") local winnerGui = Instance.new("ScreenGui") winnerGui.Parent = plrGui end
LocalPlayer
is only defined in a LocalScript that is running on the client. It is used to get the client's player, because they're the one running the script. If the script is on the server, nobody is running it locally, so there is no local player.
Instead, what you want to do is iterate through every player.
function winnerGui() for _,plr in pairs(game.Players:GetPlayers())do local plrGui = plr:WaitForChild("PlayerGui") local winnerGui = Instance.new("ScreenGui") winnerGui.Parent = plrGui end end