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

How would I properly execute a function if a bool is true?

Asked by 9 years ago

I have a bool called Driverswin in the workspace. How would I make a script that when that bool is true it does a fuction called like Message or something?

1 answer

Log in to vote
2
Answered by
4Bros 550 Moderation Voter
9 years ago

I'm assuming you want that function to fire everytime that bool is changed to true, rather than checking if it's true just one time. To do this, you need to use the bool's Changed event, it will return a parameter of the boolvalue's value which can be either true or false.

local workspace = game:GetService'Workspace'
local bool = workspace:WaitForChild'BoolValue' -- Change what is inside the apostraphes to the boolvalue's name

function Message()
    local message = Instance.new("Hint",workspace)
    message.Text = "This is a message"
    game:GetService'Debris':AddItem(message,4) 
end


bool.Changed:connect(function(value) -- This will fire every time the boolvalue is changed
    if value then --If bool value is true
        Message() -- Call message
    end
end)


Ad

Answer this question