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

Why does my script doesn't react to Bolean value?

I made this script, everything looks fine but it don't react when the value is true...

if script.Parent.Parent.Bool == true then
	for i = 1,70 do
		script.Parent.Position.Z = script.Parent.Position - Vector3.new(0,0,0.05)
		wait(0.001)
	end
	wait(5)
	for i = 1,70 do
		script.Parent.Position.Z = script.Parent.Position + Vector3.new(0,0,0.05)
	end
end

I changed the default name of the BoolValue because the game don't understand when i call Value.Value idk if it can cause problems.

I am very confused about Bolean value right now, I tough it was easy to use lol! Thank you in advance !

2 answers

This is because a BoolValue has a property called Value which is where you can read/write the bool from

if script.Parent.Parent.Bool.Value == true then
    for i = 1,70 do
        script.Parent.Position.Z = script.Parent.Position - Vector3.new(0,0,0.05)
        wait(0.001)
    end
    wait(5)
    for i = 1,70 do
        script.Parent.Position.Z = script.Parent.Position + Vector3.new(0,0,0.05)
    end
end


3 comments

0

A bolean value is true or false isn't it? so if i set the Bool.Value to true this chunck of script should run shouldn't it?

0

@Louix27626 thats correct!

0

So, idk why it doesn't work :S

you need to register an event listener to to the Bool value

because if you just write the following code, then when the game starts it will immediately run the code, only once..

if script.Parent.Parent.Bool == true then
    for i = 1,70 do
        script.Parent.Position.Z = script.Parent.Position - Vector3.new(0,0,0.05)
        wait(0.001)
    end
    wait(5)
    for i = 1,70 do
        script.Parent.Position.Z = script.Parent.Position + Vector3.new(0,0,0.05)
    end
end

but if you register an event handler to the bool value then the code will always run everytime that an event occurs;

the event you can use is called Changed. and here is how you can use it..

local bool = game.etc.ect.Bool -- change to directory of the bool value

bool.Changed:Connect(function()
	if script.Parent.Parent.Bool == true then
	    for i = 1,70 do
	        script.Parent.Position.Z = script.Parent.Position - Vector3.new(0,0,0.05)
	        wait(0.001)
	    end
	    wait(5)
	    for i = 1,70 do
	        script.Parent.Position.Z = script.Parent.Position + Vector3.new(0,0,0.05)
	    end
	end
end)

note: Changed listens for when any changes occur on the subject object; you can use GetPropertyChangedSignal to listens for only a single property like so:

local bool = game.etc.ect.Bool -- change to directory of the bool value

bool:GetPropertyChangedSignal("Value"):Connect(function()
	if script.Parent.Parent.Bool == true then
	    for i = 1,70 do
	        script.Parent.Position.Z = script.Parent.Position - Vector3.new(0,0,0.05)
	        wait(0.001)
	    end
	    wait(5)
	    for i = 1,70 do
	        script.Parent.Position.Z = script.Parent.Position + Vector3.new(0,0,0.05)
	    end
	end
end)

the above code only listens for when the Value Property changes~

you can find out more about events on:

Youtube

Roblox API reference

thank you!

4 comments

0

Thank you for your answer but it's still not working idk why. Basically I have a button with a script when you press on it the BoolValue = true (should i do BoolValue = not BoolValue instead?) and the script I already showed you

0

lemme redo my answer to try and accommodate for what ur trying to do

0

also btw, is the button a click detector or just a GUI button; and if it it's a GUI do you have a server script or localscript in it? and if its a click detector, do you have a localScript or server script in it??

0

there's 2 buttons with a serverscript and a click detector in a model the serverscript is in the model not the buttons (Door > ButtonModel, BoolValue > script, click detector, button1, button2)

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