I have event called "PlayerDiedTo" that is supposted to pass names of things that killed the player to local script so it can check if the thing that killed player was named "CorrectPart"
I tried this but I just started learning about events and dont know how this works
local event = game.ReplicatedStorage.PlayerDiedTo event.OnClientEvent:Connect(function(CorrectPart) if CorrectPart then print("Correct") else print("False") end end)
script.Parent.Touched:Connect(function(Hit) if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid")then if Hit.Parent:FindFirstChild("NPC") then --ignore this it just detects if hit parent is not an npc else Hit.Parent.Humanoid.Health = 0 local event = game.ReplicatedStorage.PlayerDiedTo local CorrectPart= script.Parent event:FireAllClients(CorrectPart) end end end)
There is no need to pass it through events, just do this
--Script inside the tool you are using to kill someone (a sword for example) Tool = script.Parent Handle = Tool.Handle local Player = game.Players:GetPlayerFromCharacter(Tool.Parent) or Tool.Parent.Parent --1. checks if there is a character (so if they are equipped the tool), if no then 2. checks the tool parent which is the backpack, and the backpack is parented to the player Handle.Touched:Connect(function(hit) local Tagged = Instance.new("ObjectValue") Tagged.Name = "creator" Tagged.Value = Player Tagged.Parent = hit.Parent.Humanoid game:GetService("Debris"):AddItem(Tagged, 2) end) --Script inside the character (place inside startercharacterscripts) local Character = script.Parent local Humanoid = char:WaitForChild("Humanoid") Humanoid.Died:Connect(function() local creator = Humanoid:FindFirstChild("creator) if creator then local plr = creator.Value if plr and plr.leaderstats then plr.leaderstats.Kills.Value +=1 --replace with whatever you want to change, may be cash or something end end end)