I have been trying to script a buttongui to set a boolean value to false and true like a switch, but I can’t really understand how. I am incredibly new to scripting and have no idea how to do it.
I have searched the devforum for answers but don’t understand it.
I want variable runs to become false once the buttongui is clicked, and become true again once buttongui is clicked again.
local ScreenGui=script.Parent
local START=ScreenGui.START
local runs = true
START.MouseButton1Click:Connect(function()
repeat
local randompos = math.random (-300, -100)
local randompos1 = math.random (120 ,320)
print (randompos, randompos1)
local PartCount=0
local spawnpart=Instance.new (“Part”)
spawnpart.Anchored=false
spawnpart.Position = Vector3.new (randompos1, 60, randompos)
spawnpart.Parent=game:GetService(“Workspace”)
game.ReplicatedStorage.PartCount.Value = game.ReplicatedStorage.PartCount.Value + 1
print(“Part count: “… game.ReplicatedStorage.PartCount.Value…””)
task.wait()
until runs == false
end)
local enabled = false -- By default, enabled is false
enabled = not enabled -- This changes the value of enabled to the opposite of 'false', which is 'true'
-- 'enabled' is now true
enabled = not enabled -- This changes the value to the opposite once more
-- 'enabled' is now false again