Gui Button Not Working

Ive been coding UI for years but its just stopped working.

script.Parent.Roll.MouseButton1Click:Connect(function()
		if not canClick then return end
		ButtonTween:Play()
		canClick = false



		script.Parent.Cooldown.Visible = true
		local fakeRewards, reward = game.ReplicatedStorage.Functions.RNG:Invoke()

		script.Parent.RollFrame.RewardContainer.RewardText.Text = reward[1]
		script.Parent.RollFrame.RewardContainer.RewardChance.Text = '1 in '..tostring(reward[2])


		script.Parent.RollFrame.Visible = true
		game.ReplicatedStorage.Functions.CooldownStart:Invoke()
		print("Cooldown")
		wait(2)
		ButtonTween1:Play()
		wait(1)
		script.Parent.RollFrame.Visible = false
		script.Parent.Cooldown.Visible = false
		canClick = true
end)


image
this is what it looks like

there are also no errors and ive tried print() and it didnt do anything so the problem is the button itself but idk

2 Likes

There are a couple of things that I notice:

The problem: The variable canClick is my guess as to why it doesn’t work. It probably isn’t getting set to true

Organization: Your code is very unorganized and repetitive.

All of those lines take up a lot of space and are hard to follow. Creating a variable for each on would be much more effective.

local button = script.Parent.Roll
local cooldown = script.Parent.Cooldown
local rng_function = game.ReplicatedStorage.Functions.RNG
local reward_text = script.Parent.RollFrame.RewardContainer.RewardText
local reward_chance = script.Parent.RollFrame.RewardContainer.RewardChance
local rollframe = script.Parent.RollFrame
local start_cooldown = game.ReplicatedStorage.Functions.CooldownStart

button.MouseButton1Click:Connect(function()
	if not canClick then return end
	ButtonTween:Play()
	canClick = false
	
	local fakeRewards, reward = rng_function:Invoke()
	
    cooldown.Visible = true
	
	reward_text.Text = reward[1]
	reward_chance.Text = '1 in '..tostring(reward[2])

	rollframe.Visible = true

	start_cooldown:Invoke()
	print("Cooldown")
	task.wait(2)
	
	ButtonTween1:Play()
	
	task.wait(1)
	
	rollframe.Visible = false
	cooldown.Visible = false
	
	canClick = true
end)

Back to the actual issue, for more assistance I will need to see what causes the canClick variable to change. If it starts as false then the button can’t ever be clicked.

it does start on true. Is there anything else causing this

It is possible that either your RNG function of Cooldown function aren’t returning anything, so the script just waits forever.