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

for loop for timer countdown is not working. why is that?

I have this code where a raid starts and then soldiers arrive with a countdown but the for loop of it isn't working. Why? i put print in it, it worked. here is code:

oldier1Clone.Humanoid.Died:Connect(function()
			wait(1.5)
			workspace.ApartmentHouse.EntranceDoor.ProximityPrompt.Enabled = true
			local timer = 7
			
			for i = timer, 1, -1 do
				--wait(1)
				ReplicatedStorage.TimerStatus.Value = "Soldier Incomming in: " .. i

				if ReplicatedStorage.TimerStatus.Value == "Soldier Incomming in: 1" then
					wait(1)
					ReplicatedStorage.TimerStatus.Value = "Soldier Incomming in: 0"

					local newSoldier = Soldiers.Soldier4:Clone()

					newSoldier.Damage.Value = 35

					newSoldier.Parent = workspace.NPCS
					newSoldier.Humanoid.MaxHealth = 10000
					newSoldier.Humanoid.Health = 10000
				end	
				
				if workspace.ApartmentHouse.EntranceDoor.ProximityPrompt.Triggered then
					break
				end
			end
	
			soldier2Clone.Parent = workspace.NPCS
			soldier2Clone:MoveTo(workspace.ApartmentHouse.EnterDoor.CFrame.Position)		
		end)

1 answer

✓ Accepted answer

Line 23, ProximityPrompt.Triggered is an event, not a boolean value so it cannot be used in an if statement.

Use an event to check when the ProximityPrompt was triggered and modify a boolean value.

soldier1Clone.Humanoid.Died:Connect(function()
	local promptTriggered = false

	workspace.ApartmentHouse.EntranceDoor.ProximityPrompt.Triggered:Connect(function()
		promptTriggered = true
	end)

	wait(1.5)
	workspace.ApartmentHouse.EntranceDoor.ProximityPrompt.Enabled = true
	local timer = 7
	
	for i = timer, 1, -1 do
		--wait(1)
		ReplicatedStorage.TimerStatus.Value = "Soldier Incomming in: " .. i
		
		if ReplicatedStorage.TimerStatus.Value == "Soldier Incomming in: 1" then
		wait(1)
		ReplicatedStorage.TimerStatus.Value = "Soldier Incomming in: 0"
		
		local newSoldier = Soldiers.Soldier4:Clone()
		
		newSoldier.Damage.Value = 35
		
		newSoldier.Parent = workspace.NPCS
		newSoldier.Humanoid.MaxHealth = 10000
		newSoldier.Humanoid.Health = 10000

		if promptTriggered == true then
			break
		end
	end

	soldier2Clone.Parent = workspace.NPCS
	soldier2Clone:MoveTo(workspace.ApartmentHouse.EnterDoor.CFrame.Position)       
end)

2 comments

0

Click "View Source" on the top right corner of the code if you have trouble reading it

0

thanks it worked!

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