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

How to check True or False During Script Run?

So I fixed some problems with my Toaster. But I realized as I was testing it that I missed a pretty big thing.

So although my improved script prevents the Toaster from turning on while unplugged, it DOESN'T know if it's plugged in or not WHILE it's already on.

So it doesn't shut off while it's running

Here's the script that when you press it it starts the Toaster up:

Plugged = workspace.ToasterCord:WaitForChild("Plugged")


function onClicked(playerWhoClicked)
	if Plugged.Value == true then
	script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, -0.4, 0)
	wait(0.7)
	script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0.4, 0)
	wait(6)
	workspace.Toaster.Heat1.BrickColor = BrickColor.new("Dusty Rose")
	workspace.Toaster.Heat2.BrickColor = BrickColor.new("Dusty Rose")
	wait(6)
    workspace.Toaster.Heat1.BrickColor = BrickColor.Red()
	workspace.Toaster.Heat2.BrickColor = BrickColor.Red()
	wait(8)
	workspace.Toaster.Heat1.BrickColor = BrickColor.new("Really red")
	workspace.Toaster.Heat2.BrickColor = BrickColor.new("Really red")
	wait(10)
	script.Parent.Parent.Base.Smoke.Enabled = true
	wait(12)
	script.Parent.Parent.Base.Smoke.Opacity = 0.3
	wait(30)
	script.Parent.Parent.Base.Smoke.Opacity = 1
	wait(10)
	script.Parent.Parent.Base.Fire.Enabled = true
	script.Parent.Parent.Base.PointLight.Enabled = true
	if Plugged.Value == false then 
		script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, -0.1, 0)
		wait(0.2)
		script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0.1, 0)
	
	end
	


end
end
 

2 answers

Your second if statement (Line 27) never runs if your first one (Line 5) is not true. To solve this, place one of the ends before the second if statement. Check this out:

Plugged = workspace.ToasterCord:WaitForChild("Plugged")


function onClicked(playerWhoClicked)
    if Plugged.Value == true then
    script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, -0.4, 0)
    wait(0.7)
    script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0.4, 0)
    wait(6)
    workspace.Toaster.Heat1.BrickColor = BrickColor.new("Dusty Rose")
    workspace.Toaster.Heat2.BrickColor = BrickColor.new("Dusty Rose")
    wait(6)
    workspace.Toaster.Heat1.BrickColor = BrickColor.Red()
    workspace.Toaster.Heat2.BrickColor = BrickColor.Red()
    wait(8)
    workspace.Toaster.Heat1.BrickColor = BrickColor.new("Really red")
    workspace.Toaster.Heat2.BrickColor = BrickColor.new("Really red")
    wait(10)
    script.Parent.Parent.Base.Smoke.Enabled = true
    wait(12)
    script.Parent.Parent.Base.Smoke.Opacity = 0.3
    wait(30)
    script.Parent.Parent.Base.Smoke.Opacity = 1
    wait(10)
    script.Parent.Parent.Base.Fire.Enabled = true
    script.Parent.Parent.Base.PointLight.Enabled = true
    end
    if Plugged.Value == false then 
        script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, -0.1, 0)
        wait(0.2)
        script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0.1, 0)




end
end

Your false check is inside of the true check, so it will never execute.

Plugged = workspace.ToasterCord:WaitForChild("Plugged")
function onClicked(playerWhoClicked)
	if Plugged.Value == true then
		-- Code for true value
	elseif Plugged.Value == false then
		-- Code for false value
	end
end

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