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

Help with a shockwave?

I need help with this shockwave script, if two shockwaves overlap, instead of going through each other, they climb over each other. Any ways to combat this?

wait(2)
script.Parent.Transparency = 0
for i = 1, 300 do
script.Parent.CFrame=script.Parent.CFrame*CFrame.new(0,0,0.1)
script.Parent.Size = script.Parent.Size + Vector3.new(0.2,0,0)
wait(0)
end
script.Parent:Destroy()

2 comments

0

Anchor the parts?

0

that doesnt work.. :(

2 answers

✓ Accepted answer

Try storing the position, changing the size then set the cframe to that position

wait(2)
script.Parent.Transparency = 0

for i = 1, 300 do
	local cf = script.Parent.CFrame*CFrame.new(0,0,0.1)
	script.Parent.Size = script.Parent.Size + Vector3.new(0.2,0,0)
	script.Parent.CFrame=cf
	wait(0)
end

script.Parent:Destroy()

The problem here is that when you change the .Size of a part, if it overlaps with anything, it will move on top to make room.

You can set .CFrame to combat this behavior -- but you have to know where it was before the problematic shifting around from changing the Size.


Depending on the context, it can be better to make changes relative to where you are now (like you do in line 4), but it is often cleaner to be relative to where you started:

local home = script.Parent.CFrame
local size = script.Parent.Size
for i = 1, 300 do
	script.Parent.CFrame = home * CFrame.new(0, 0, 0.1 * i)
	script.Parent.Size = size + Vector3.new(0.2 * i, 0, 0)
	wait()
end
script.Parent:Destroy()

Also keep in mind that the amount of time wait will pause for is variable, and it can be good practice to actually use the time that has elapsed.

A loop written like this (not relative to where it was in the previous step) is a lot easier to transform into that, since you can just replace i with the time elapsed times some factor:

local started = tick()
repeat
	local elapsed = tick() - started
	local i = elapsed * 30
	script.Parent.CFrame = home * CFrame.new(0, 0, 0.1 * i)
	script.Parent.Size = size + Vector3.new(0.2 * i, 0, 0)
	wait()
until elapsed > 10
script.Parent:Destroy()

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