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

The points value wont increase, how do I make my two loops co-exist?

	function onPlayerEntered(newPlayer)

    	local stats = Instance.new("IntValue")
    	stats.Name = "leaderstats"

    	local points = Instance.new("IntValue")
    	points.Name = "Currency"
    	points.Value = 0

		local Prison = Instance.new("IntValue")
    	Prison.Name = "Prison"
    	Prison.Value = 10

    	stats.Parent = newPlayer 
    	points.Parent = stats
		Prison.Parent = stats

    	while true do
		wait(1)	
				if Prison.Value >= 1 then
				Prison.Value  = Prison.Value - 1
			end
		end
		
		while true do
		wait(2)
				points.Value = points.Value + 50
			end
    	end
	
game.Players.PlayerAdded:connect(onPlayerEntered)

4 answers

✓ Accepted answer
    function onPlayerEntered(newPlayer)

        local stats = Instance.new("IntValue")
        stats.Name = "leaderstats"

        local points = Instance.new("IntValue")
        points.Name = "Currency"
        points.Value = 0

        local Prison = Instance.new("IntValue")
        Prison.Name = "Prison"
        Prison.Value = 10

        stats.Parent = newPlayer 
        points.Parent = stats
        Prison.Parent = stats


x = false -- set a boolean so that it can detirmine if its the correct time to go
while wait(1) do
 if Prison.Value >= 1 then
                Prison.Value  = Prison.Value - 1
            end
if x then -- this will make it so every 1 second it wont go, but 2 seconds it will
x = false
points.Value = points.Value + 50
else
x = true
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)

1 comment

0

@ikiled You just forgot one end. Heh, other than that it worked great! Thanks so much!

I would not recommend doing that. putting anything below a while true do loop will not work unless it's in another function. and it wont repeat due to it only working once as it is in a player added function.

you cant have 2 loops running at the same time on 1 script, what the computer does is read the script, can you read 2 books at the exact same time?

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