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

How can I stop this simple script from breaking?

Asked by 10 years ago
repstorage.RoundTag.Changed:connect(function(value)
    if value == true then
        if repstorage.GameRound.Value == "Deathmatch" then
            for _, player in pairs(game.Players:GetPlayers()) do
                player.Character:WaitForChild("Humanoid").Died:connect(function()
                    if player.Character.Humanoid:FindFirstChild("creator") then
                        local tag = player.Character.Humanoid.creator
                        local tColor = player.TeamColor
                        local kColor = tag.Value.TeamColor
                        if not kColor then return end
                        if not tColor then return end
                        if tColor ~= kColor then
                            if kColor == BrickColor.new("Lime green") then
                                greenscore.Value = greenscore.Value + 1
                            elseif kColor == BrickColor.new("New Yeller") then
                                yellowscore.Value = yellowscore.Value + 1
                            end
                        end
                    end
                end)
            end
        end
    end
end)

I have this script which checks if the round value changes then it sets off. So the game is 5 minutes long, and when a person dies it gives the team + 1 point. The problem is that it gives you a point but if you kill someone again then you dont get the points. How come this dosent work? There is no outpout errors

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

The WaitForChild method doesn't return the child you're waiting for, it returns the loop of time to wait until the child isn't nil. On line 5 you used it to index the Humanoid.

repstorage.RoundTag.Changed:connect(function(value)
    if value == true then
        if repstorage.GameRound.Value == "Deathmatch" then
            for _, player in pairs(game.Players:GetPlayers()) do
                player.Character:WaitForChild("Humanoid")
                player.Character.Humanoid.Died:connect(function()
                    if player.Character.Humanoid:FindFirstChild("creator") then
                        local tag = player.Character.Humanoid.creator
                        local tColor = player.TeamColor
                        local kColor = tag.Value.TeamColor
                        if not kColor then return end
                        if not tColor then return end
                        if tColor ~= kColor then
                            if kColor == BrickColor.new("Lime green") then
                                greenscore.Value = greenscore.Value + 1
                            elseif kColor == BrickColor.new("New Yeller") then
                                yellowscore.Value = yellowscore.Value + 1
                            end
                        end
                    end
                end)
            end
        end
    end
end)
0
still dosent work, even adark tried and it dosent work but idk why NinjoOnline 1146 — 10y
Ad

Answer this question