Script Not Working as Intended

Hello There!
I am trying to Make A “Spike” System in which Randomly Selected Spikes Rise Above the Ground
and You Have to Dodge Them.

First, A Red Spot appears on where the Spike will Rise and then The Spike Arises.
The Problem Is that The “Spikes” Arise One by One and not all At Once

I want Them to Come all At Once.

Here is The Script

I use for i,v in pairs for the Spikes. Which makes them Arise One by One. Is there anything I can Use Other Than That to Make Spikes Arise all At once?

				wait(0.15 * 13) -- Marked All Red (Ignore This)
				game.Workspace.Sounds.Spikes.Volume = 1
				game.Workspace.Sounds.Spikes:Play()
				
				for i,v in pairs(game.Workspace.Arena.Spikes:GetChildren()) do
					if v:FindFirstChild("SpikeRed").Transparency == 0 then
						v.SpikeRed.Transparency = 1
						v.Position = Vector3.new(v.Position.X,v.Position.Y + 5,v.Position.Z)
						wait(4) -- Spikes Closing Back
						v.Position = Vector3.new(v.Position.X,v.Position.Y - 5,v.Position.Z)
					end
				end

Try using coroutine.wrap

for i,v in pairs(game.Workspace.Arena.Spikes:GetChildren()) do
    coroutine.wrap(function()
    	if v:FindFirstChild("SpikeRed").Transparency == 0 then
		    v.SpikeRed.Transparency = 1
		    v.Position = Vector3.new(v.Position.X,v.Position.Y + 5,v.Position.Z)
			wait(4) -- Spikes Closing Back
		    v.Position = Vector3.new(v.Position.X,v.Position.Y - 5,v.Position.Z)
		end
	end)()
end
1 Like

this will yield your loop for 4 seconds each index preventing the other spikes from moving

1 Like