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

How do I make this localscript wait for the character before it runs?

Asked by
Drogb4 15
11 years ago

Okay so I got this and it works perfectly fine in testmode but it doesn't do anything at all in a normal server, does anyone know what is the problem?

01player = game.Players.LocalPlayer
02system = game.workspace.system
03 
04 
05function onDeath()
06system.playersalive.Value = system.playersalive.Value -1
07player.CameraMode="Classic"
08system.joindeadmsg.Value = player.Name .. " has died."
09end
10 
11 player.Character.Humanoid.Died:connect(onDeath)

OUTPUT:

14:46:41.106 - Players.Player1.PlayerGui.maingui.ondead:10: attempt to index field 'Character' (a nil value)

14:46:41.106 - Stack Begin

14:46:41.107 - Script 'Players.Player1.PlayerGui.maingui.ondead', Line 10

14:46:41.108 - Stack End

2 answers

Log in to vote
0
Answered by 11 years ago

Use the :WaitForChild() event

Example

1local Player = game.Players.LocalPlayer
2local Character = Player:WaitForChild("Character")
0
I did that, but it didn't work and now don't get output at all Drogb4 15 — 11y
0
its because its still waiting for the character DragonSkyye 517 — 11y
0
try using the :FindFirstChild() event if not WaitForChild DragonSkyye 517 — 11y
Ad
Log in to vote
0
Answered by 11 years ago
01player = game.Players.LocalPlayer
02player.CharacterAdded:wait()
03system = game.workspace.system
04 
05 
06function onDeath()
07system.playersalive.Value = system.playersalive.Value -1
08player.CameraMode="Classic"
09system.joindeadmsg.Value = player.Name .. " has died."
10end
11 
12player.Character.Humanoid.Died:connect(onDeath)

Answer this question