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

Works in play solo, but not online mode?

Asked by
Dom2d2 35
11 years ago
01player = script.Parent.Parent
02thrust = game.ReplicatedStorage.BodyThrust
03force = game.ReplicatedStorage.BodyForce
04f = force:Clone()
05f.Parent = player.Character.Head
06while true do
07    locationX = player.Character.Head.Position.X
08locationY = player.Character.Head.Position.Y
09locationZ = player.Character.Head.Position.Z
10    m = Instance.new("Part")
11    m.Shape = "Ball"
12    m.Size = Vector3.new(1,1,1)
13    m.CanCollide = false
14    t = thrust:Clone()
15    t.Parent = m
View all 21 lines...

This is my script, the issue is, that it works entirely fine in play solo, but doesn't work at all in online mode. The error I get is: 11:41:29.475 - Players.Player1.PlayerGui.LocalScript:7: attempt to index field 'Character' (a nil value) 11:41:29.475 - Script 'Players.Player1.PlayerGui.LocalScript', Line 7

1 answer

Log in to vote
0
Answered by
duckwit 1404 Moderation Voter
11 years ago

Oftentimes the Player loads in such a way that the LocalScript in question will start running before the actual Workspace representation of the Character has loaded, so common practice when dealing with a LocalScript is to wait() for certain things to exist, like-so:

1while not game.Players.LocalPlayer do wait() end
2player = game.Players.LocalPlayer
3while not player.Character do wait() end
4character = player.Character
5while not character.Head do wait() end
6head = character.head

That way you won't be trying to index a field that doesn't exist yet. It took me a long while to figure out why my LocalScripts were breaking in Online mode, too!

Ad

Answer this question