Any idea why this doesn't stop the number from incrementing after every click?
game.ReplicatedStorage.PartCreate.OnServerEvent:Connect(function() for _,v in pairs(game.Players:GetChildren()) do local runCount = 0 if runCount == 0 then v.PlayerGui.ScreenGui.ScrollingFrame.Frame.TxtVotes.Text = v.PlayerGui.ScreenGui.ScrollingFrame.Frame.TxtVotes.Text + 1 print("Voted") runCount = runCount + 1 print(runCount) end end end)
I'm not exactly sure what you're trying to accomplish here, however I believe the problem that you're having is because you are setting the value runCount
to 0 every time the loop runs. To fix your problem (if I'm understanding this properly), all you have to do is set the value on line 2. Your new script would look like this:
local runCount = 0 game.ReplicatedStorage.PartCreate.OnServerEvent:Connect(function() for _,v in pairs(game.Players:GetChildren()) do if runCount == 0 then v.PlayerGui.ScreenGui.ScrollingFrame.Frame.TxtVotes.Text = v.PlayerGui.ScreenGui.ScrollingFrame.Frame.TxtVotes.Text + 1 print("Voted") runCount = runCount + 1 print(runCount) end end end)
Let me know if this doesn't fix your problem.