I made a Script in ServerScriptStorage, it's deposed to detect if a player kills or gets killed and print when these events happen. The sword creates a creator tag in the humanoid but my script won't print the message. What's the problem?
Script:
01 | local players = game.GetService( "Players" ) |
02 |
03 | players.PlayerAdded:Connect( function (player) |
04 |
05 | player.CharacterAdded:Connect( function (character) |
06 |
07 | local humanoid = character:WaitForChild( "Humanoid" ) |
08 | humanoid.Died:Connect( function () |
09 | print ( "You died!" ) |
10 | if humanoid:FindFirstChild( "creator" ) ~ = nil then |
11 | local Killer = humanoid.creator.Value |
12 | print ( "You're the killer!" ) |
13 | end |
14 |
15 | end ) |
16 | end ) |
17 | end ) |
Maybe try putting it in ServerScriptService.
01 | local players = game.GetService( "Players" ) |
02 |
03 | players.PlayerAdded:Connect( function (player) |
04 | local character = player.Character or player.CharacterAdded:Wait() |
05 | local humanoid = character:WaitForChild( "Humanoid" ) |
06 | local creator = humanoid:FindFirstChild( "creator" ) |
07 |
08 | humanoid.Died:Connect( function () |
09 | print ( "You died!" ) |
10 | end ) |
11 |
12 | creator.Changed:Connect( function () |
13 | if creator.Value ~ = nil then |
14 | local Killer = creator.Value |
15 | print ( "You're the killer!" ) |
16 | end |
17 | end ) |
18 | end ) |
I hope this helped!
The problem is in your first line of code, try this:
1 | local players = game:GetService( "Players" ) |
you made a error on the first line
01 | local players = game:GetService( "Players" ) |
02 |
03 | players.PlayerAdded:Connect( function (player) |
04 |
05 | player.CharacterAdded:Connect( function (character) |
06 |
07 | local humanoid = character:WaitForChild( "Humanoid" ) |
08 | humanoid.Died:Connect( function () |
09 | print ( "You died!" ) |
10 | if humanoid:FindFirstChild( "creator" ) ~ = nil then |
11 | local Killer = humanoid.creator.Value |
12 | print ( "You're the killer!" ) |
13 | end |
14 |
15 | end ) |
16 | end ) |
17 | end ) |
try this script