Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I stop this simple script from breaking?

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

✓ Accepted answer

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)

1 comment

0

still dosent work, even adark tried and it dosent work but idk why

This discussion is preserved as it was. New answers, comments, and votes are closed.