My code doesn’t work.
-
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.
-
What is the issue? It doesn’t change the values.
-
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!