0

Click Button Doesn't Work ;( (it says that there is no error)?

variable = game.StarterGui.ScreenGui.Numbers.TextLabel.hi
game.StarterGui.ScreenGui.Frame.TextButton.MouseButton1Down:Connect(function()
variable.Value = variable.Value + 1
game.StarterGui.ScreenGui.Numbers.TextLabel.Text = "Clicks:"..variable.Value
end)



I was confused when i was writing this script because when i tested it didnt work ;(.

0
Edited 5 months ago

First thing, don't ever use 'game.StarterGui' or anything as its content gets copied to the separate folder, which is located in the Player, called 'PlayerGui'.

Second, you haven't used a 'local' while creating the variable.

Also, it should be a LocalScript.

Here, I am assuming that your contents are in a single ScreenGui. The simplest of fixing it to use 'script.Parent'. So, in your script, the edits should be:

variable = script.Parent.Parent.Numbers.TextLabel.hi -- Here 'script.Parent.Parent' is the parent of the TextButton, where your script is.
script.Parent.MouseButton1Down:Connect(function()
variable.Value = variable.Value + 1
script.Parent.Parent.Numbers.TextLabel.Text = "Clicks:"..variable.Value
end)

-- Do change the 'script.Parent' according to your location in your game.


Lemme know if it helps!