Mousebutton1click only fires once/ not at all

I am making a counter which adds up when you click on a button. It uses a IntValue as a holder for how many times you have clicked.

  1. What do you want to achieve? A counter.

  2. What is the issue? It won’t add/subtract.

  3. What solutions have you tried so far? I have tried debouncing and other things. I may have missed some details or I may have done something wrong. There is no error showing (I am new and so sorry for cringe code)

For now, it looks like this inside the button

-- local script lololol
local count = script.Parent.Parent.Parent.tick
local label = script.Parent
-- label is the button, i just reused my code

label.MouseButton1Click:Connect(function()
	count.Value = count.Value + 1
end)
2 Likes

Hi there. What object class is label? Assuming it is a TextLabel based on the name, TextLabels do not have any event named MouseButton1Click as they cannot be clicked or pressed.

1 Like

its the button, sorry for missing details

1 Like

have you tried print() to check if it fires?

1 Like

it does fire, however…

image

it doesnt update the intvalue…

pardon me for my informalities but I think I do now know how did it go through the update statement without, well, updating it

is it local script? (charcter limit)

1 Like

And there’s your answer. LocalScripts do not run when used as a descendent to the workspace. Use it under a local service instead such as StarterPlayerScripts and correctly re-reference your button and that’ll be your fix.

False assumption that the LocalScript was a descendant of workspace.

1 Like

Yes about that…

image

It is in StarterGui. I do not understand.

As an alternative, I will try putting it on StarterPlayerScripts.

Try printing count.Value after you incremented its value.

1 Like

Please disregard my comment on the workspace placement then. StarterGui is completely fine location for LocalScripts and you do not need to replace the code to StarterPlayerScripts.

1 Like

image

It actually counted it… but I still don’t understand why it won’t show up on the IntValue (and the TextLabel I used to display this value)

I’ll keep testing…

I believe it’d help to point that out that contents of StarterGui get automatically cloned and parented to your LocalPlayer.PlayerGui folder when you connect. So while observing value changes on the explorer, make sure you’re not checking the StarterGui, but the PlayerGui objects instead.

For the value update to the TextLabel, how is the TextLabel being updated?

1 Like

Ah, I assume you’re checking the GUI from StarterGui instead of Players.LocalPlayer.PlayerGui.

1 Like

It checks the IntValue if it gets changed by tick.Changed (i reuse my own code way too much sorry) and changes appropriately by the value of the IntValue.

And also the IntValue is in the StarterGui folder so maybe that’s the reason why it won’t update.

Nevermind, it worked now.

I just had to change the references.

(Apparently, you can’t do stuff like

local count = int.Value)

Should have known earlier. Thank you all though.

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