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

Game is working fine in Solo, but not in server?

I have a simple script that works fine when in Studio Solo mode, but when on any kind of server (even with just one person), it doesn't work.

script.Parent.MouseButton1Click:connect(function(player)
	game.Players.LocalPlayer.Character:MoveTo(Vector3.new(-5, 1.89, -61.6))
end)

It just gives the error "attempting to index field 'LocalPlayer' (a nil value)". I have a LocalScript in the StarterGui.

1 answer

✓ Accepted answer

Try this out in a Local Script. Works for me in my game.

script.Parent.MouseButton1Down:connect(function()
	wait(0.1)
	game.Players.LocalPlayer.Character:MoveTo(Vector3.new(-5, 1.89, -61.6))
end)

And if adding only a certain team.

player = game.Players.LocalPlayer

script.Parent.MouseButton1Down:connect(function()
	wait(0.1)
	if player.TeamColor == game.Teams['Citizens'].TeamColor then
	game.Players.LocalPlayer.Character:MoveTo(Vector3.new(-5, 1.89, -61.6))
end
end)

2 comments

0

So I just moved my script over onto a LocalScript and it worked. But why is that? How does having it in a LocalScript vs. a script change anything?

0

Wait, I'm just stupid. I forgot that the LocalPlayer property only works when it is used in a LocalScript, not regular scripts. That was my problem. Thanks for the help!

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