Studio doesn't recognize the local player

Hey gamers, I’ve been trying to fix this for a long time but haven’t been able to find a solution.
For some reason, I get an error at line 5; Players.Fox_2042.PlayerGui.Menu.Buttons.Play.Click:5: attempt to index nil with 'Team'.
I don’t know what I can do to make the game recognize the local player. Nothing I try works.

Here’s the scipt.

local plr = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function(plr)
 	plr.Team = script.Parent.Parent.SelectedTeam.Value
	plr:LoadCharacter()
end)
1 Like

Is this in a LocalScript?

This text will be blurred

1 Like

No, I had tried it with a local script but the same error occurred.

1 Like

Well the LocalPlayer property does not exist on the server for fairly obvious reasons (because it’s the server…) so there’s no point in trying this with a normal Script, try debugging with a LocalScript

2 Likes

You’re overriding the plr variable by the functions value. Do this instead:

local plr = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
 	plr.Team = script.Parent.Parent.SelectedTeam.Value
	plr:LoadCharacter()
end)

and also do it on the client, and LoadCharacter doesn’t work on the client. So you will need to use a remote event

3 Likes

Worked, thanks!
Funny, I’ve tried using a local script and tried removing plr but never both at once lmaoa

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.