-
What do you want to achieve? Keep it simple and clear!
I want all the parts inside the model of this tree to change colors when it reaches a certain threshold of health. -
What is the issue? Include screenshots / videos if possible!
everything BUT the changing color part doesn’t work.
This is the error in question (i really hope the embed works) -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Tried skimming around the forums, but nothing really worked. Unless I did something incorrect, I’m really not sure. I’m fairly new to scripting and the sorts so any type of advice would be appreciated.
This is what the tree looks like
local tree = script.Parent
local treeHum = tree.Humanoid
local parts = {}
for i, part in pairs(tree:GetChildren()) do
if part:isA("Part") then
table.insert(parts, part)
end
end
function healthChange()
if tree:GetAttribute("health1") == false and treeHum.Health <= treeHum.MaxHealth * 3/4 then
tree:SetAttribute("health1", true)
for i, part in pairs(parts) do
local r = part.color.R * 255
local g = part.Color.G * 255
local b = part.Color.B * 255
part.color = Color3.fromRGB(r - 20, g - 20, b - 20)
end
end
end
treeHum:GetPropertyChangedSignal("Health"):Connect(healthChange)