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

Player killed player message error repeatedly typing creator message?

Asked by 4 years ago
Edited 4 years ago

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)
0
Hello! We've noticed you have made a post with extremely long code. Trimming your code will attract more answers and will be easier to understand. For more information see: https://idownvotedbecau.se/TooMuchCode/ User#30567 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Hello, you can add a debounce in order to prevent something to repeat continuously. Also you can try adding wait() this might help too.

Ad

Answer this question