How do I make a loop run however many times a number value is, without changing the value?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to make a loop run however many times the number value is, without changing the value.

  2. What is the issue? I have no clue what to do.

  3. What solutions have you tried so far? I looked it up multiple different ways but I couldn’t find what I was looking for.

while wait(0.5) do
	for i,plr in pairs(game.Players:GetChildren()) do
		 ammountofjump = plr.Potions.JumpPotions
		if plr.team == game.Teams.Playing then
			print("Playing")
			if ammountofjump.Value >= 1 then
				wait(1)
				local jumpclone = game.ServerStorage.Potions.JumpPotion:Clone()
				jumpclone.Parent = plr.Backpack
				ammountofjump.Value = ammountofjump.Value - 1
				end
end
end

I am making a round based game, and I made a number value that is named JumpPotions. The value of it is how many jump potions the player has. Im kinda making a inventory system. But if I add a script that saved progress, if they leave while the game is running the value will be zero and they will save with no potions. Now I need to figure out how I do what was listed in the title.

have you tried adding another value and copying the new value’s value to the first value’s value, then you can change the value of the 2nd one instead?

Yes, but it is a loop so the second value gets reset to the first.

yes but then you can change the 2nd value to the first value again after the end of the loop
cycle

but everytime it runs again it get reset to the first value so it stays at the first value and doesnt go down.

you’re using a number value as the number right?

Yeah im using the value of the number

wait im a bit confused: are you trying to go from 0 to the first value’s value?
or: are you trying to count the amount of loops it does?
or: are you trying to loop the amount of times the first value’s value?

So basically, you can buy a potion from the shop, then the value of it goes up, then it gives you that many potions that the value has once the round starts.

I already tried that but the value gets reset after every loop.

couldnt you just add another counter? and make the value: counter - 1 every time you use the potions and counter + 1 everytime you buy a potion?

Yeah, I never thought of that, it might get a little messy though because of how many potions I have.

maybe try having a limit amount of potions allowed after every round? like 2 potions every round so its not too op and solves your problem?

Yes I did that, it just that there will be so many different potions.

If you can customize this to your script, it does work for me

local Value = game.Workspace:FindFirstChild("Value").Value

for count = 1, Value do
	print("Looping... Goal: "..Value.." times")
end
wait()
print("Finished!")
Value = 0

well, it will be messy, but you will find out how to make it simpler once you make it the first time.

Mine happens literally instantly, to add delay do:

local Value = game.Workspace:FindFirstChild("Value").Value

for count = 1, Value do
	print("Looping... Goal: "..Value.." times")
    wait(1)  
end
wait()
print("Finished!")
Value = 0

I will try this, if it doesnt work than I will do what the NoobDev did.

This was kinda my first post, so thankyou.

No problem, change it to this though. Found an error resetting it to 0

local Value = game.Workspace:FindFirstChild("Value")

for count = 1, Value.Value do
	print("Looping... Goal: "..Value.Value.." times")
	wait(1)  
end
wait()
print("Finished!")
Value.Value = 0

Basically now the variable is just the value itself, then doing .Value to get it’s value