Hi guys, I’m making a sword fighting game where the game would check whether the player killed another. This code doesn’t seem to be working.
local playerchars = {}
local function CD(ds1,ds2)
return (ds1-ds2).magnitude
end
workspace.ChildAdded:Connect(function(character)
if character:IsA("Model") and character:WaitForChild("HumanoidRootPart",2) and not table.find(playerchars,character) then
table.insert(playerchars,character)
character:WaitForChild("Humanoid").Died:Connect(function()
for _, char in pairs(playerchars) do
if char:FindFirstChild("ClassicSword") and table.find(workspace:GetPartsInPart(char.ClassicSword.Handle),character.PrimaryPart or Instance.new("Part")) then
--We now have access to the reference of the killer, and the killed person
local killer = game.Players:GetPlayerFromCharacter(char)
local killed = game.Players:GetPlayerFromCharacter(character)
game.ReplicatedStorage.Notify:FireAllClients(killer.Name.." has killed "..killed.Name.." from "..math.floor(CD(character.Head.Position,char.Head.Position)).." studs away")
table.remove(playerchars,table.find(playerchars,character))
break
end
end
end)
end
end)