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)