When clicking button it dosent give me clicks

Hello Guys!

I have created a script where if you click a textbutton it should give you clicks but it isn’t working.

Script

local Clicks = game.Players.LocalPlayer.Data:WaitForChild("PlayerData").Currency
local Button = game.StarterGui.GameUI.Frame.TextButton


Button.MouseButton1Click:Connect(function()
	Clicks.Value = Clicks.Value + 1
end)
1 Like

This is because you’re looking for the button in StarterGui instead of the button that’s under the player.

Instead, switch it to something along the lines of script.Parent.GameUI.Frame.TextButton. To make this even easier though, I suggest you parent the local script under the button and then have the script state:

local Clicks = game.Players.LocalPlayer.Data:WaitForChild("PlayerData").Currency
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	Clicks.Value += 1 -- += is equivalent to doing { value = value + otherValue }
end)

And if you plan to use the player later in this script, I suggest you define them as a variable and then switch clicks to something along the lines of local Clicks = player.Data:WaitForChild("PlayerData").Currency

2 Likes

Thank you very much! now i want to know how to script so you can’t click the button untill 1 minute has gone by and after that you can’t click it at all

1 Like

All you’d have to do for that is use task.wait() and then input the number of seconds you want to wait. You may have seen people use wait() but task.wait() is a better alternative as it is faster and more reliable.

1m = 60s so:

task.wait(60) should work.

1 Like

How would I implement it into my script?

Hey StarJ3M are you there???

I was busy but you will have to implement a debounce.

if the debounce is false, then the code will run, but if the debounce is true, then it won’t. This essentially means that if the cooldown (debounce) isn’t active, then we can click the button, and vice versa.

local Clicks = game.Players.LocalPlayer.Data:WaitForChild("PlayerData").Currency
local Button = script.Parent

local cooldown = false -- debounce is a boolean that will say whether the lines of code after it will run.

Button.MouseButton1Click:Connect(function()
	if not cooldown then 
		Clicks.Value += 1 -- += is equivalent to doing { value = value + otherValue }
		
		cooldown = true -- we make the debounce true so that when the button's clicked
		-- the next time, we don't allow it to give the player another click.

		task.wait(5) -- we wait five seconds, change this to anything you'd like.
		cooldown = false -- now when we click the button we will gain a click.
	end
end)

@planeboy2021

1 Like

That completey breaks my game unfortunately @StarJ3M

How so? Could you describe what’s happening?

My ui dosen’t work it dosen;t let me sprint

The button UI or all of your UI? Try reverting it, it may just be the other scripts.

1 Like

My tutorial GUI dosent seem to be working

1 Like

Seems to be working now because i had a frame active

2 Likes

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