I'm working on a basic wave spawner, I need this loop to end after it runs a certain amount of time.
local spawnamount = game.Workspace.Live.spawnamount.Value local multiplier = 20 -- the amount that will eventually add onto the total amount after a wave. local shrieker = game.ReplicatedStorage.Shrieker while true do wait(1) local shriekerclone = shrieker:Clone() shriekerclone.Parent = workspace shriekerclone.HumanoidRootPart.Position = game.Workspace.spawnpart.Position end
have no idea what to do here, I can usually find something on the wiki to help me but not today so.
Running it for a certain amount of time...you can use a variable and add onto every second, and then use an if then
statement to determine if the variable is the amount of seconds that have passed, then using break
to break the loop
For example;
local spawnamount = game.Workspace.Live.spawnamount.Value local multiplier = 20 -- the amount that will eventually add onto the total amount after a wave. local shrieker = game.ReplicatedStorage.Shrieker local seconds = 0 -- your new variable while true do wait(1) seconds = seconds + 1 -- adding a second every time if seconds == 6 then -- lets say you want this to go on for 6 seconds break -- breaks the loops else -- its not at desired time local shriekerclone = shrieker:Clone() shriekerclone.Parent = workspace shriekerclone.HumanoidRootPart.Position = game.Workspace.spawnpart.Position end end
Though I took the format you used, while true do
, you can also use the repeat - until
loop
Example;
local spawnamount = game.Workspace.Live.spawnamount.Value local multiplier = 20 -- the amount that will eventually add onto the total amount after a wave. local shrieker = game.ReplicatedStorage.Shrieker local seconds = 0 -- your new variable repeat seconds = seconds + 1 -- adding a second every time local shriekerclone = shrieker:Clone() shriekerclone.Parent = workspace shriekerclone.HumanoidRootPart.Position = game.Workspace.spawnpart.Position wait(1) until seconds == 6 -- repeating until variable "seconds" = 6
Links:
https://developer.roblox.com/en-us/articles/Conditional-Statements-in-Lua
https://developer.roblox.com/en-us/articles/Loops
Hope this helps