Answered by
7 years ago Edited 7 years ago
When it says
attempt to index field 'Character' (a nil value)
then that means the Character has not yet loaded into the game. Thus meaning you need to wait for the character to load. Now there are many different ways of doing this. One way is to set a repetition until the player loads.
1 | repeat wait() until Player.Character |
this waits until the player is present before continuing through the script. This is one of the shortest methods of doing so.
Another way is to set a CharacterAdded function
1 | Player.CharacterAdded:connect( function () |
this method enables you to do something to the character at the moment of it loading.
I hope this helped you and if not feel free to comment and I will assist you further.
Here is a script you may try
03 | local Player = game.Players.LocalPlayer |
04 | local repstorage = game.ReplicatedStorage |
05 | local Char = Player.Character or Player.CharacterAdded:Wait() |
06 | local part 1 = game:FindFirstChild( 'PART1Clone' ) |
07 | local part 2 = game:FindFirstChild( 'PART2Clone' ) |
08 | local event = repstorage.ServerEvent |
09 | local activated = game.ReplicatedStorage.On |
13 | repeat wait() until Char.Humanoid |
14 | Player.Character.Humanoid.Died:connect( function () |
18 | activated.Value = false |