01 | player = script.Parent.Parent |
02 | thrust = game.ReplicatedStorage.BodyThrust |
03 | force = game.ReplicatedStorage.BodyForce |
04 | f = force:Clone() |
05 | f.Parent = player.Character.Head |
06 | while true do |
07 | locationX = player.Character.Head.Position.X |
08 | locationY = player.Character.Head.Position.Y |
09 | locationZ = player.Character.Head.Position.Z |
10 | m = Instance.new( "Part" ) |
11 | m.Shape = "Ball" |
12 | m.Size = Vector 3. new( 1 , 1 , 1 ) |
13 | m.CanCollide = false |
14 | t = thrust:Clone() |
15 | t.Parent = m |
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
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:
1 | while not game.Players.LocalPlayer do wait() end |
2 | player = game.Players.LocalPlayer |
3 | while not player.Character do wait() end |
4 | character = player.Character |
5 | while not character.Head do wait() end |
6 | head = 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 LocalScript
s were breaking in Online mode, too!