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

Why won't my Script print a message when player is killed or kills?

Asked by 3 years ago

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:

01local players = game.GetService("Players")
02 
03players.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)
17end)

3 answers

Log in to vote
0
Answered by 3 years ago

Maybe try putting it in ServerScriptService.

01local players = game.GetService("Players")
02 
03players.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)
18end)

I hope this helped!

Ad
Log in to vote
0
Answered by 3 years ago

The problem is in your first line of code, try this:

1local players = game:GetService("Players")
Log in to vote
0
Answered by 3 years ago

you made a error on the first line

01local players = game:GetService("Players")
02 
03players.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)
17end)

try this script

Answer this question