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

How do I loop this script to respawn the "Tsunami Wave" after 60 seconds?

function onTouched(hit)
hit:BreakJoints()
end
while true do
	
script.Parent.Touched:connect(onTouched)
wait(5)
script.Parent.Size = Vector3.new(205.9,10,159.5)
script.Parent.Position = Vector3.new(275.085,0.5,-334.35)
script.Parent.BrickColor = BrickColor.Blue()
script.Parent.Transparency = .3
script.Parent.Material =Enum.Material.Glass
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,1)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,1,2)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,3)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,1,4)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,5)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,1,6)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,7)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,1,8)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,9)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,1,10)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,11)
wait(60)
wait()
end

1 comment

0

After the wave moves forward and ultimately falls off the map being destroyed I want to loop the cycle again. Maybe something is wrong with my "while true do"?

2 answers

Create a separate function for the wave generation.

-- Dictionary for vector3 values
local Vector3Dict = {
[1] = Vector3.new(0,0,1),
[2] = Vector3.new(0,1,2),
[3] = Vector3.new(0,0,3),
[4] = Vector3.new(0,1,4),
[5] = Vector3.new(0,0,5) -- and so on...
}

local function CreateWave(Object)
	Object.Size = Vector3.new(205.9,10,159.5)
	Object.Position = Vector3.new(275.085,0.5,-334.35)
	Object.BrickColor = BrickColor.Blue()
	Object.Transparency = .3
	Object.Material =Enum.Material.Glass
	for i = 1,5,1 do
		wait(.1)
		Object.CFrame = Object.CFrame + Vector3Dict[i] -- changes vec3
	end
end

while true do
	script.Parent.Touched:connect(onTouched) 
	wait(5)
	CreateWave(script.Parent)
	wait(60)
end

something like this should work.

I think this should do it.

function onTouched(hit)
hit:BreakJoints()
end
while wait(60) do

script.Parent.Touched:connect(onTouched)
wait(5)
script.Parent.Size = Vector3.new(205.9,10,159.5)
script.Parent.Position = Vector3.new(275.085,0.5,-334.35)
script.Parent.BrickColor = BrickColor.Blue()
script.Parent.Transparency = .3
script.Parent.Material =Enum.Material.Glass
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,1)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,1,2)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,3)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,1,4)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,5)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,1,6)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,7)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,1,8)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,9)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,1,10)
wait(.1)
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,0,11)
end

3 comments

0

Thanks for teaching me how to use loops much more effectively. It worked, you're great!

0

while wait() do is bad practice.

0

when you use while wait() do it has to evaluate if wait() is truthy, it returns 2 values making it slower than while true do wait()

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