Something wrong with my script

Hi, I was making a script, when I tested it, it didn’t work:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent == game.Workspace.Map then
		if script.Parent.AssemblyLinearVelocity.Y < -5 then
			script.Parent:Destroy()
		end
	end
end)

this script is to see if the parent is touching something in the model called Map and if the speed is below -5 but the script does not work, when I put it to check only if it is touching a part the script works but if i put it to check speed too does’t work.

Anyone know how to solve?

  • I’m new with programmng

  • I only built this script because another guy helped me.

We don’t get paid and we all have school or jobs. Some posts don’t get answered for hours or more.

I think your issue is that when it touches something, it bounces and so the velocity is not less than five. If this doesn’t need to be CanCollide, you can turn that off and it should be fixed. If it does need to collide, then you might consider something like this.

local velocity = 0
script.Parent.Touched:Connect(function(hit)
	if hit.Parent == game.Workspace.Map then
		if velocity < -5 then -- Use the velocity from .1 seconds ago.
			script.Parent:Destroy()
		end
	end
end)

while task.wait(.1) do -- Update the old velocity every .1 seconds.
    velocity = script.Parent.AssemblyLinearVelocity.Y
end

your script works, the object really kicks when it touches, thanks.

Sorry for commenting this, when I create a post someone is already responding

1 Like