01 | player = game.Players.LocalPlayer |
02 | system = game.workspace.system |
03 |
04 |
05 | function onDeath() |
06 | system.playersalive.Value = system.playersalive.Value - 1 |
07 | player.CameraMode = "Classic" |
08 | system.joindeadmsg.Value = player.Name .. " has died." |
09 | end |
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
Use the :WaitForChild()
event
Example
1 | local Player = game.Players.LocalPlayer |
2 | local Character = Player:WaitForChild( "Character" ) |
01 | player = game.Players.LocalPlayer |
02 | player.CharacterAdded:wait() |
03 | system = game.workspace.system |
04 |
05 |
06 | function onDeath() |
07 | system.playersalive.Value = system.playersalive.Value - 1 |
08 | player.CameraMode = "Classic" |
09 | system.joindeadmsg.Value = player.Name .. " has died." |
10 | end |
11 |
12 | player.Character.Humanoid.Died:connect(onDeath) |