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

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

Asked by
gobrett 11
5 years ago
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

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"? gobrett 11 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Ad
Log in to vote
-1
Answered by 5 years ago

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
0
Thanks for teaching me how to use loops much more effectively. It worked, you're great! gobrett 11 — 5y
0
while wait() do is bad practice. SaltyPotter 362 — 5y
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() SaltyPotter 362 — 5y

Answer this question