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

How do you make if and else statements using bool values?

Asked by 4 years ago
Edited 4 years ago

I've tried putting this script inside a fire object using the boolvalue "flareson"

if game.workspace.flareson.value = true 
then script.Parent.Enabled = true
else script.Parent.Enable = false

but the fire object is on, even though flareson's value property is unchecked.

0
I think there's a 'd' missing from Enabled on the last line. Was that in the script of just a typo in the question? NoahsRebels 99 — 4y
0
Likely a typo. billybobRAE 41 — 4y

2 answers

Log in to vote
2
Answered by
mc3334 649 Moderation Voter
4 years ago

To constantly sense the status of an object, do this:

game.Workspace:WaitForChild("flareson").Changed:Connect(function(IsOn)--IsOn will return as the value of the flare
    script.Parent.Enabled = IsOn
end)

Short and sweet. With further questions/comments/concerns, feel free to reply. Happy scripting! ~mc3334

Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

your syntax is wrong it should be

function flareson()
    if game.Workspace.flareson.Value == true then
        script.Parent.Enabled = true
    else
        script.Parent.Enabled = false
    end
end

you need two equal signs when comparing values in an if statement, only one is needed when setting/changing values

Answer this question