Countdown System, Need Help

Hello, so i make a Countdown when a player Join is creating a Folder with the player UserId and put in IntValue. Now the problem is I don’t know how to make that every second in all the userId folder that are in the server changes the value of -1

image
So, this is my actual code

local ServStorage = game.ServerStorage
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	-- Setup UserId Folder
	local NewUserFolder = Instance.new("Folder")
	NewUserFolder.Name = player.UserId
	NewUserFolder.Parent = ServStorage:WaitForChild("StandCountdownPlayers")

	-- Setup Timer Instance
	local OpenStandTimer = Instance.new("IntValue")

	-- Setup Timer Names
	OpenStandTimer.Name = "OpenStandTimer"

	-- Setup Timer Folder
	OpenStandTimer.Parent = NewUserFolder
end)

Players.PlayerRemoving:Connect(function(player)
	ServStorage.StandCountdownPlayers:WaitForChild(player.UserId):Destroy()
end)

I think i can use For but i dont know how

The Principe if is not clear " every 1s is change all value in all UserId folder of to -1 like if is 2 is now 1"

You Can Do It with A simple loop, but first you have to set the amount of time that you want for your count down for example:

local ServStorage = game.ServerStorage
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	-- Setup UserId Folder
	local NewUserFolder = Instance.new("Folder")
	NewUserFolder.Name = player.UserId
	NewUserFolder.Parent = ServStorage:WaitForChild("StandCountdownPlayers")

	-- Setup Timer Instance
	local OpenStandTimer = Instance.new("IntValue")

	-- Setup Timer Names
	OpenStandTimer.Name = "OpenStandTimer"

	-- Setup Timer Folder
	OpenStandTimer.Parent = NewUserFolder
	OpenStandTimer.Value = 3 -- the time of count down
	
	local finish = false
	while wait(1) do -- this loop will run every 1 sec
		OpenStandTimer.Value = OpenStandTimer.Value - 1
		if OpenStandTimer.Value == 0 then -- checks if the countdown is finnished
			finish = true
			break -- it will breaks the loop
		end
	end
	if finish == true then
		-- your action here
		end
end)

Players.PlayerRemoving:Connect(function(player)
	ServStorage.StandCountdownPlayers:WaitForChild(player.UserId):Destroy()
end)
2 Likes

Thank you, but the problem is that I want to be able to use the countdown aprais if ever the value is new greater than 0 except that

Edit
I think have idea

1 Like

@3MASTER9 Thx you, i modified you script and now is make what i need !
So for infomartion this is the script

	--Timer System
while wait(1) do
		if ServStorage.StandCountdownPlayers:FindFirstChild(player.UserId) then
		if OpenStandTimer.Value > 0 then
		OpenStandTimer.Value = OpenStandTimer.Value - 1	
		end
		else
		break -- it will breaks the loop
		end
	end
1 Like

Good Job, glad that i did something which helped you to fix this problem :smile: :sweat_smile:

1 Like