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

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

Asked by
emite1000 335 Moderation Voter
10 years ago

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

Log in to vote
0
Answered by
DevWork 80
10 years ago

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)
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? emite1000 335 — 10y
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! emite1000 335 — 10y
Ad

Answer this question