Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is the count not increasing?

What I'm trying to do is when the player clicks a brick a GUI in the corner of there screen will add by 1

The number is not changing and there is no error in the output

Count = 0
Collect = script.Parent


function OnClicked()
	Count = Count + 1
	game.StarterGui.ScreenGui.TextLabel.Text = Count 
end

Collect.ClickDetector.MouseClick:Connect(OnClicked)

2 comments

0

Items in StarterGui that are modified with a script will only be seen after the player respawns. You may have to make a RemoteEvent that fires a LocalScript to change the number on the client's side right away.

0

maybe you need to add the PlayerWhoClicked parameter in your function since it's required for the MouseClick event?

1 answer

✓ Accepted answer

What you're doing wrong is you are changing the value in the starter gui instead of the player gui. What you need the script to read is down below:

local Count = 0
local Collect = script.Parent

function OnClicked(player)
    Count = Count + 1
    player.PlayerGui.ScreenGui.TexxtLabel.Text = Count 
end

Collect.ClickDetector.MouseClick:Connect(OnClicked)

the reason I typed player in the parentheses if because the listeners of the MouseClick event get us the player that clicked the part, so all we need to do is change the text from there.

Hope I helped.

This discussion is preserved as it was. New answers, comments, and votes are closed.