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
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
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.
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)