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

How to I stop it from repeating?

Asked by 3 years ago

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)
0
id suggest doing what the guy who just answered said. I would ALSO suggest, line 9 to be "greater than or equal" or "less than or equal to", often times, counts can skip a beat if coded wrongly. greatneil80 2647 — 3y
0
I also accidentally set the value on the wrong line, my new answer should work now though. cmgtotalyawesome 1418 — 3y

1 answer

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

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.

0
ive tried that but it keeps repeating. Shadrocks12345 0 — 3y
Ad

Answer this question