Script does not see change in value

You can write your topic however you want, but you need to answer these questions:
I’m trying to make a part changing color depending on its power value (Between 0 and 100), and it works fine, until I change the value, and the script does not see the change in the value. Idk what is happening, I really need help.

Current code:

local black = Color3.new(0, 0, 0) --Black color
local glowcolor = Color3.new(0, 1, 1) --Glow color

while task.wait(0.05) do --Loop forever
	local c = black:Lerp(glowcolor, script.parent.Charge.Value/100) --Lerp the two colors and store result in a variable
	script.Parent.Glow.Color = c --Update part color
	if script.parent.Charge.Value > 100 then --Regulate between 0 and 100
		script.parent.Charge.Value = 100
	end
	if script.parent.Charge.Value < 0 then
		script.parent.Charge.Value = 0
	end
end

How are you changing the Value?

Use math.clamp instead, It should help set a Limit between Values, like so:

script.parent.Charge.Value = math.clamp(script.parent.Charge.Value, 0, 100)

-- Will not go below 0 or over 100

Right now, I’m manually changing the value with the command line, but later I’ll do it with scripts.

Thanks for the tip!

Is the Script ran on the Client or the Server? And are you Applying the Changes on the Client, or Server?

The server doesn’t seem to see the changes (In other words the change appears to be client-side), how do I fix that?

Well, Since you are applying the changes to the Client, You can use the Developer Console (Press F9 or Enable in Settings) by Switch the mode from Client to Server (which should be next to the search bar), and then typing in a line of code at the Command Line at the Bottom of the Developer Console Window, or you can switch to the Server View by going to the topbar and pressing Current Client, which should allow you to make server changes

Thanks, is there a way to make sure my changes are always server-side?

A Server Script (or just Script),
But those as far as I know are the only ways to do it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.