Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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


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? Louix27626 83 — 5y
0
@Louix27626 thats correct! DanzLua 2879 — 5y
0
So, idk why it doesn't work :S Louix27626 83 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

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 Louix27626 83 — 5y
0
lemme redo my answer to try and accommodate for what ur trying to do User#23252 26 — 5y
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?? User#23252 26 — 5y
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) Louix27626 83 — 5y

Answer this question