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)
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)