Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is the count not increasing?

Asked by 4 years ago

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)
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. Pianotech 48 — 4y
0
maybe you need to add the PlayerWhoClicked parameter in your function since it's required for the MouseClick event? aipiox123 1 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Ad

Answer this question