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

Why my script doesn't detect the value change?

Hi, I tried to do a few scripts that are based on changing values, but the problem is, not any of them detected that the value has changed when it did change.

Here's one of the them:

while true do
	wait(script.Parent.Parent.Open.Changed)
if script.Parent.Parent.Open.Value == true then
	print("value changed")
		wait(2)
		script.Parent.Color = Color3.fromRGB(0,255,0)
		script.Parent.SurfaceLight.Color = Color3.fromRGB(0,255,0)
		wait(14)
		for i= 0,5 do
			script.Parent.Color = Color3.fromRGB(255, 0, 0)
			script.Parent.SurfaceLight.Color = Color3.fromRGB(255, 0, 0)
			wait(0.2)
			script.Parent.Color = Color3.fromRGB(0,0,0)
			script.Parent.SurfaceLight.Color = Color3.fromRGB(0,0,0)
			wait(0.2)
		end
		wait(2)
		script.Parent.Color = Color3.fromRGB(255,255,255)
		script.Parent.SurfaceLight.Color = Color3.fromRGB(255,255,255)
else
	print("value didn't chaged")
	script.Parent.Color = Color3.fromRGB(255,255,255)
	script.Parent.SurfaceLight.Color = Color3.fromRGB(255,255,255)
end
end

The prints were show if the value did changed but it kept printing "value didn't changed". Any help is appreciated, thank you.

Edit 1: even with the shorten Open.changed:connect() method: the script doesn't detect the bool's value change.

2 answers

✓ Accepted answer

You don't need a while true do loop to detect if a value was changed..

There is an event for that already!

local open = script.Parent.Parent.Parent.Open

open.Changed:Connect(function()
	-- code for when open is changed
end)

this is all you should need!

4 comments

0

Thanks for this shorten method! But the script still doesn't detect the change. I'm going to start thinking that I'm cursed lol.

0

That method does work. The value isn't being changed or your if statements are running because you're checking for the wrong thing

0

Make you you are checking if everything is correct and is there script printing "Changed"

0

After a lot of test, it did worked! I don't know why, but I should fix my studio. Thank you so much for your help!

is the Open a bool value? if yes you are missing a .Value in the end of the if condiction:


if script.Parent.Parent.Open.Value == true then --fixed version

1 comment

0

Yes it is a bool value, but it still doesn't detect the bool value's change with the version you gave me.

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