Trying to make a button unable to be pressed whilst another script is active

Hi, I am making an RNG game and I have been trying to implement an auto roll feature. The feature itself works fine however I need it to be so that when a player manually rolls the auto roll button cannot be pressed as it seems that when it is pressed whilst the main script is active it results in breaking the auto feature.

This is the script for the main roll button

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FormatNumber = require(ReplicatedStorage.FormatNumber.Simple)
local plr = script.Parent.Parent.Parent.Parent
local Auto = plr.Auto.Auto

local canClick = true
		while wait(0.1) do
			if plr.Auto.Auto.Value == 0 then
			
				if not canClick then return end
			canClick = false
			local fakeRewards, reward = game.ReplicatedStorage.Function:Invoke()
			local myString = reward[4]
			local splitted = string.split(myString, ", ")
			local colour = Color3.fromRGB(tonumber(splitted[1]), tonumber(splitted[2]), tonumber(splitted[3]))
	
			script.Parent.Parent.RollFrame.RewardContainer.RewardText.Text = reward[1]
			script.Parent.Parent.RollFrame.RewardContainer.RewardChance.Text = '1 in '..tostring(FormatNumber.FormatCompact(reward[2]))
			script.Parent.Parent.RollFrame.RewardContainer.RewardPrice.Text = '$'..FormatNumber.FormatCompact(reward[3])
			script.Parent.Parent.RollFrame.RewardContainer.RewardText.TextColor3 = Color3.fromRGB(tonumber(splitted[1]), tonumber(splitted[2]), tonumber(splitted[3]))
			script.Parent.Parent.RollFrame.Visible = true
			wait(2)
			script.Parent.Parent.RollFrame.Visible = false
			canClick = true
			
			
			elseif plr.Auto.Auto.Value == 1 then
			script.Parent.MouseButton1Click:Connect(function()
				if not canClick then return end
			canClick = false
			plr.CanClick.CanClick.Value = 0
			local fakeRewards, reward = game.ReplicatedStorage.Function:Invoke()
			local myString = reward[4]
			local splitted = string.split(myString, ", ")
			local colour = Color3.fromRGB(tonumber(splitted[1]), tonumber(splitted[2]), tonumber(splitted[3]))

			script.Parent.Parent.RollFrame.RewardContainer.RewardText.Text = reward[1]
			script.Parent.Parent.RollFrame.RewardContainer.RewardChance.Text = '1 in '..tostring(FormatNumber.FormatCompact(reward[2]))
			script.Parent.Parent.RollFrame.RewardContainer.RewardPrice.Text = '$'..FormatNumber.FormatCompact(reward[3])
			script.Parent.Parent.RollFrame.RewardContainer.RewardText.TextColor3 = Color3.fromRGB(tonumber(splitted[1]), tonumber(splitted[2]), tonumber(splitted[3]))
			script.Parent.Parent.RollFrame.Visible = true
			wait(2)
			script.Parent.Parent.RollFrame.Visible = false
			canClick = true
			end)
		
			
			end
		
	
		end


and this is the script for the auto button

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local plr = script.Parent.Parent.Parent.Parent
local FormatNumber = require(ReplicatedStorage.FormatNumber.Simple)

local ting = true
			script.Parent.MouseButton1Click:Connect(function()
					if ting == true then
						script.Parent.BackgroundColor3 = Color3.fromRGB(96, 255, 93)
						plr.Auto.Auto.Value = 0
						ting = false

					elseif ting == false then
						script.Parent.BackgroundColor3 = Color3.fromRGB(255, 28, 28)
						plr.Auto.Auto.Value = 1
						ting = true
						end
			end)

With Buttons you can utilize the feature “Active” or “Interactable.” I think this is what you will be looking for.

GuiObject | Documentation - Roblox Creator Hub

GuiObject | Documentation - Roblox Creator Hub

Use a BoolValue to show when the script is “active.” Then, at the start of the button click event in the auto-roll script, write “if [put the path to the Value of the boolvalue here] then return end”

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.