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

Does two different loops work in a script?

I have this script and want to know how many loops like this it can have. They need to work on the same time. Can it hold 1, 2 or more?

Wait(7)
	
local vipamount = 4 -- This variable is the amount of RIX Vips will get each time.
local amount = 2 -- This variable is the amount of RIX we will give each time.
local timedelay = 2 -- (600)This variable is the amount of seconds in between each time the RIX is rewarded
local currencyname = "RIX" -- This is the name of our Currency
local groupId = 3141417 -- Group ID from the Group ranks will be taken from

while wait(5) do 
    for _, player in ipairs(game.Players:GetPlayers()) do
		if player:InGroup(groupId) then
			if player:FindFirstChild("lederstats") then
				if player:RoleInGroup(groupId) = "RIX VIP" then
					player.leaderstats.RIX.Value = player.leaderstats.RIX.Value + vipamount
				end
			end
		end
    end
end

while wait(5) do 
    for _, player in ipairs(game.Players:GetPlayers()) do
		if player:InGroup(groupId) then
			if player:FindFirstChild("lederstats") then
				if player:RoleInGroup(groupID) = "RIX Earner" then
					player.leaderstats.RIX.Value = player.leaderstats.RIX.Value + amount
				end
			end
		end
    end
end

while wait(5) do
	for _, player in ipairs(game.Players:GetPlayers()) do
		if player:InGroup(groupId) then
			if player:FindFirstChild("leaderstats") then
				if player:RoleInGroup(groupId) = "RIXER" then
					player.leaderstats.RIX.Value = player.leaderstats.RIX.Value + vipamount
				end
			end
		end
	end
end

1 comment

0

Nice script tho

1 answer

✓ Accepted answer

You can just put all those IF's in the same while loop. But if you really want to know, you can enclose each loop into a coroutine so it all runs on a seperate thread, wich causes them all to run parralel to eachother.

while wait() do
	print('hi')
end

while wait() do
	print('bye')
end
--Will only spam hi, never prints bye.



coroutine.wrap(function()
	while wait() do
		print('hi')
	end
end)()

coroutine.wrap(function()
	while wait() do
		print('bye')
	end
end)()

--Will spam hi & bye at the same time.

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