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

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

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.

5 comments

0

Where are you changing the value?

0

It'll only print when it fires the "else". It'll never print true

0

I figured it out.

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.

1

^ you can do it through the explorer but you have to switch to server

4 answers

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

Check your other scripts one must be changing it to false

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)

1 comment

0

btw if it's too fast, lower the Y angle to like 12 or somewhere around that.

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.

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