For loop not running?

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

  1. What do you want to achieve? Keep it simple and clear!

i want to make a pls admin game

  1. What is the issue? Include screenshots / videos if possible!

the for loop dosent work???

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    yes
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local module = require(script.Assetloader)

local textService = game:GetService("TextService")
local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local donationStore = dss:GetDataStore("MainStore")
local http = game:GetService("HttpService")
local admin = nil

local Status = game:GetService("ReplicatedStorage"):WaitForChild("Status")

local Plrs = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"
	
	local donated = Instance.new("IntValue",leaderstats)
	donated.Name = "Donated"
	
	local recieved = Instance.new("IntValue",leaderstats)
	recieved.Name = "Recieved"
	
	local data
	
	local success, errormsg = pcall(function()
		data = donationStore:GetAsync(plr.UserId)
	end)
	
	if success then
		if data then
			data = http:JSONDecode(data)
			donated.Value = data[1]
			recieved.Value = data[2]
		else
			print("No previous data.")
		end
	else
		warn(errormsg)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local data = {plr.leaderstats.Donated.Value,plr.leaderstats.Recieved.Value}
	
	local success, errormsg = pcall(function()
		data = http:JSONEncode(data)
		donationStore:SetAsync(plr.UserId,data)
	end)
	
	if success then
		print("Successfully saved.")
	else
		warn(errormsg)
	end
	
	for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
		if stand.ClaimedUserName.Value == plr.Name then
			module.clearStand(stand)
		end
	end
end)

mps.PromptGamePassPurchaseFinished:Connect(function(plr,passId,purchased)
	if purchased == true then
		print("Purchased.")
		
		local item = module.findItem(passId)
		
		local cost = item.Cost.Value
		
		if cost then
			print(cost)
			plr.leaderstats.Donated.Value += cost
		else
			print("Could not find cost.")
		end
		
		if admin then
			admin.leaderstats.Recieved.Value += cost
		else
			print("Could not find PlrBy.")
		end
		
		module.updateStandsEarned()
	else
		print("Not purchased.")
	end
end)

mps.PromptPurchaseFinished:Connect(function(plr,assetId,purchased)
	if purchased == true then
		print("Purchased.")
		
		local item = module.findItem(assetId)

		local cost = item.Cost.Value

		if cost then
			print(cost)
			plr.leaderstats.Donated.Value += cost
		else
			print("Could not find cost.")
		end

		if admin then
			admin.leaderstats.Recieved.Value += cost
		else
			print("Could not find PlrBy.")
		end

		module.updateStandsEarned()
	end
end)

while wait() do
	if #Plrs:GetChildren() >= 0 then
		print("DEBUG1")
		if admin then
			print("DEBUG2")
			for _, v in ipairs(Plrs:GetChildren()) do
				module.loadItems(v.PlayerGui.Main.Products, admin.UserID)
			end
			print("DEBUG3")
			for i = 200,0,1 do <--- i havent tested this one but if the other one didnt work then i doubt this will work
				Status.Value = admin.Name.." will be admin for "..i.." Sec, put the admins product to make his/her powers stronger"
				if i == 0 then
					admin = nil
					Status.Value = "Restarting Admins..."
				end
				wait(1)
			end
			wait(2)
			print("DEBUG4")
		elseif admin == nil then
			print("DEBUG5")
			for i = 30,0,1 do -- dosent run
				print("DEBUG6")
				Status.Value = "Next Player will be chosen in "..i.." seconds"
				if i == 0 then
					local RandomPlrNumber = math.random(1, #Plrs:GetChildren())
					local RandomAdmin = Plrs[RandomPlrNumber]
					Status.Value = "Next admin will be ..."
					wait(3)
					Status.Value = RandomAdmin.Name
					admin = RandomAdmin
				end
				wait(1)
			end
			wait(2)
			print("DEBUG7")
		end
	end
end

Debug 1,5,7 runs but not 6, so all of the for loops are completely toasted

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

you gotta count down not count up

for i = 30,0,-1 do
2 Likes

oh, i was like “how will it count up if i go down.”

I’m so dumb XD.

3 Likes

i have other issues but its unrelated, and i think i can fix it myself!

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.