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

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

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

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)


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