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:
local players = game.GetService("Players") players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local humanoid = character:WaitForChild("Humanoid") humanoid.Died:Connect(function() print("You died!") if humanoid:FindFirstChild("creator") ~= nil then local Killer = humanoid.creator.Value print("You're the killer!") end end) end) end)
Maybe try putting it in ServerScriptService.
local players = game.GetService("Players") players.PlayerAdded:Connect(function(player) local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") local creator = humanoid:FindFirstChild("creator") humanoid.Died:Connect(function() print("You died!") end) creator.Changed:Connect(function() if creator.Value ~= nil then local Killer = creator.Value print("You're the killer!") end end) end)
I hope this helped!
The problem is in your first line of code, try this:
local players = game:GetService("Players")
you made a error on the first line
local players = game:GetService("Players") players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local humanoid = character:WaitForChild("Humanoid") humanoid.Died:Connect(function() print("You died!") if humanoid:FindFirstChild("creator") ~= nil then local Killer = humanoid.creator.Value print("You're the killer!") end end) end) end)
try this script