Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year ago

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

Log in to vote
0
Answered by
SirGamezy 186
1 year ago
Edited 1 year ago

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)

0
Click "View Source" on the top right corner of the code if you have trouble reading it SirGamezy 186 — 1y
0
thanks it worked! Boyuanbogosess 17 — 1y
Ad

Answer this question