So, I made code that posts message chat player who killed the player it does work but there on error when posting the message
The error: it posts the player who got killed by the creator then it repeattedly saying this ( creator creator creator creator etc.
the code
function Died() local C = script:GetChildren() for i = 1,#C do if C[i]:IsA("ObjectValue") and (C[i].Value ~= nil and C[i].Value.Parent ~= nil) then if C[i].Value:GetState() == Enum.HumanoidStateType.Dead and not C[i].Value.Parent:FindFirstChild("DeadAsRagdoll") then local End = "" local Color = Color3.new() local Color2 = Color3.new() local Amount = 0 local Font = Enum.Font.SourceSansBold local AfterName = "" if game.Players:GetPlayerFromCharacter(C[i].Value.Parent) and game.Players:GetPlayerFromCharacter(C[i].Value.Parent).Neutral == false then Color = game.Players:GetPlayerFromCharacter(C[i].Value.Parent) AfterName = " ("..tostring(game.Players:GetPlayerFromCharacter(C[i].Value.Parent)).." "..tostring((game.Players:GetPlayerFromCharacter(C[i].Value.Parent)) or " ").." " elseif C[i].Value.Parent:FindFirstChild("Torso") then Color = C[i].Value.Parent:FindFirstChild("Torso").BrickColor.Color if not game.Players:GetPlayerFromCharacter(C[i].Value.Parent) then Font = Enum.Font.SourceSansItalic else Font = Enum.Font.SourceSans end elseif C[i].Value.Parent:FindFirstChild("UpperTorso") then Color = C[i].Value.Parent:FindFirstChild("UpperTorso").BrickColor.Color if not game.Players:GetPlayerFromCharacter(C[i].Value.Parent) then Font = Enum.Font.SourceSansItalic else Font = Enum.Font.SourceSans end else Color = Color3.new(1,1,1) if not game.Players:GetPlayerFromCharacter(C[i].Value.Parent) then Font = Enum.Font.SourceSansItalic else Font = Enum.Font.SourceSans end end local C2 = C[i].Value:GetChildren() for i = 1,#C2 do if C2[i].Name == "creator" then Amount = Amount + 1 if C2[i].Value then if Amount == 1 then End = End.." "..tostring(C2[i].Value) else End = End..", "..tostring(C2[i].Value) end if C2[i].Value:IsA("Player") then if C2[i].Value.Neutral == false then End = End..' ('..tostring(C2[i])..' '..tostring((C2[i]) or " ")..'' elseif C2[i].Value.Character:FindFirstChild("Torso") then elseif C2[i].Value.Character:FindFirstChild("UpperTorso") then end end else if Amount == 1 then End = End.." by the killed NPC" else End = End..", NPC" end end end end if Amount >= 1 then game.StarterGui:SetCore("ChatMakeSystemMessage",{Text = C[i].Value.Parent.Name.." Was killed by"}) game.StarterGui:SetCore("ChatMakeSystemMessage",{Text = End..".",Color = Color2}) else game.StarterGui:SetCore("ChatMakeSystemMessage",{Text = C[i].Value.Parent.Name.." Has died."}) end local D = script:GetChildren() for i = 1,#D do if D[i]:IsA("ObjectValue") and (D[i].Value == nil or D[i].Value.Parent == nil or D[i].Value:GetState() == Enum.HumanoidStateType.Dead) or D[i].Value.Parent:FindFirstChild("DeadAsRagdoll") then D[i]:Destroy() end end end else C[i]:Destroy() end end end local D = game.Workspace:GetDescendants() for i = 1,#D do if D[i]:IsA("Humanoid") then local IsInList = false local C = script:GetChildren() for i = 1,#C do if C[i].Value == D[i] then IsInList = true end end if IsInList == false then local ObjVal = Instance.new("ObjectValue",script) ObjVal.Name = tostring(D[i].Parent) ObjVal.Value = D[i] D[i].Died:connect(Died) end end end function DescendantAdded(item) if item:IsA("Humanoid") then local IsInList = false local C = script:GetChildren() for i = 1,#C do if C[i].Value == item then IsInList = true end end if IsInList == false then local ObjVal = Instance.new("ObjectValue",script) ObjVal.Name = tostring(item.Parent) ObjVal.Value = item item.Died:connect(Died) end end end game.Workspace.DescendantAdded:connect(DescendantAdded)
Hello, you can add a debounce
in order to prevent something to repeat continuously. Also you can try adding wait()
this might help too.