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
10 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?

player = game.Players.LocalPlayer
system = game.workspace.system


function onDeath()
system.playersalive.Value = system.playersalive.Value -1
player.CameraMode="Classic"
system.joindeadmsg.Value = player.Name .. " has died."
end

 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 10 years ago

Use the :WaitForChild() event

Example

local Player = game.Players.LocalPlayer
local Character = Player:WaitForChild("Character")
0
I did that, but it didn't work and now don't get output at all Drogb4 15 — 10y
0
its because its still waiting for the character DragonSkyye 517 — 10y
0
try using the :FindFirstChild() event if not WaitForChild DragonSkyye 517 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
player = game.Players.LocalPlayer
player.CharacterAdded:wait()
system = game.workspace.system


function onDeath()
system.playersalive.Value = system.playersalive.Value -1
player.CameraMode="Classic"
system.joindeadmsg.Value = player.Name .. " has died."
end

player.Character.Humanoid.Died:connect(onDeath)

Answer this question