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

Script is constantly printing false, even though the value is set to true?

Asked by 4 years ago
Edited 4 years ago
while true do
    wait(0.01)
    if script.Parent.Parent.On.Value == true then
        script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1,0)
    else
        print(script.Parent.Parent.On.Value)
    end
end

It just spam prints false in the output. If I set the boolean to true, and then play, the fan spins but doesn't stop when I change the boolean to false.

0
Where are you changing the value? iOwn_You 543 — 4y
0
It'll only print when it fires the "else". It'll never print true niroqeo 123 — 4y
0
I figured it out. MrOinkerzYT 87 — 4y
0
iOwn_You made me remember that I have to use a script to change the value, and I can't do it manually through the explorer. MrOinkerzYT 87 — 4y
1
^ you can do it through the explorer but you have to switch to server misha123 83 — 4y

4 answers

Log in to vote
0
Answered by 4 years ago

Something must be changing it to false, see if you have any other scripts that change the value of it

Ad
Log in to vote
0
Answered by 4 years ago

Check your other scripts one must be changing it to false

Log in to vote
0
Answered by
Gojinhan 353 Moderation Voter
4 years ago
Edited 4 years ago

I made your script more procedural, using a while loop (with an if statement too) to update a fan even if it isn't on is a waste of resources, you should rely on events in scenarios like this.

local run = game:GetService("RunService")

local connection

local what = script.Parent

script.Parent.Parent.On.Changed:Connect(function(value)
    connection = (value == true and run.Heartbeat:Connect(function(step)
          what.CFrame *= CFrame.Angles(0, 120 * step, 0)
    end)) or (connection and connection:Disconnect()) or connection
end)
0
btw if it's too fast, lower the Y angle to like 12 or somewhere around that. Gojinhan 353 — 4y
Log in to vote
0
Answered by 4 years ago

Here is the issue: It can only print false. Heres why: So, in the script, you use an if statement, saying if the value is true, then it runs other code WITHOUT printing true. If its false, it prints the value, which would of course be, false.

Basically, that is saying: If it is false, it prints the value (which would be false) If it is true, it doesn't print anything and runs other code.

Answer this question