Why doesn't my code work?

My code doesn’t work.

  1. What do you want to achieve? My code, it is supposed to add to a value when a child of an object is touched, and subtract another value.

  2. What is the issue? It doesn’t change the values.

  3. What solutions have you tried so far? I tried another way to change the value, but it didn’t work.

My code is below.

local cubes = script.Parent.Paintableparts:GetChildren()
local numUnpainted = game.ReplicatedStorage.PercentageValues.NumUnpainted
local numRed = game.ReplicatedStorage.PercentageValues.NumRed
local numBlue = game.ReplicatedStorage.PercentageValues.NumBlue

for i,v in pairs(cubes) do
	v.Touched:Connect(function(hit)
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

		if plr then
			if v.BrickColor == BrickColor.new("Medium stone grey") then
				if plr.TeamColor == BrickColor.new("Bright red") then
					numUnpainted.Value = numUnpainted.Value - 1
					numRed.Value = numRed.Value + 1
				elseif plr.TeamColor == BrickColor.new("Bright blue") then
					numUnpainted.Value = numUnpainted.Value - 1
					numBlue.Value = numBlue.Value + 1
				end
			end
			if v.BrickColor == BrickColor.new("Bright red") then
				if plr.TeamColor == BrickColor.new("Bright blue") then
					numRed.Value = numRed.Value - 1
					numBlue.Value = numBlue.Value + 1
				end
			elseif v.BrickColor == BrickColor.new("Bright blue") then
				if plr.TeamColor == BrickColor.new("Bright red") then
					numBlue.Value = numBlue.Value - 1
					numRed.Value = numRed.Value + 1
				end
			end
		end
	end)
end

Please help!

1 Like

Do any error messages appear in console?

1 Like

No, nothing shows up in the output.

1 Like

add a print(“a”) after you touched the part, so above the local plr

1 Like

It showed the print. Hmmm. Help please.

Did you try printing after every if statement to see if it gets pass ur if statements?

1 Like

Yes! I sure did. I wonder what to do.

1 Like

Two questions…

  1. Is this a local script or a server script

  2. Where is this script located?

1 Like
  1. it is a server script

  2. it is located in the maps model

1 Like