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

How to I stop it from repeating?

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)

2 comments

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.

0

I also accidentally set the value on the wrong line, my new answer should work now though.

1 answer

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.

1 comment

0

ive tried that but it keeps repeating.

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