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

How would I find the speed of a moving part?

This is a script I made that if the part touches something and its X velocity is higher than 20 it prints "touched" but I realized that the numbers would go into the negatives. How would I find the speed of the part without it going into the negatives?

local vel = script.Parent.Parent.Parent.Parent.Part.Velocity.X
local minvel = 20
script.Parent.Touched:Connect(function()
	if not debounce then
		if vel > minvel then
			debounce = true
			print("touched")
			wait(0.5)
			debounce = false

		end
	end
end)

1 answer

In order to make the velocity positive, you can use the math.abs() in the math library.

local vel = script.Parent.Parent.Parent.Parent.Part.Velocity.X
local minvel = 20
script.Parent.Touched:Connect(function()
    if not debounce then
        if math.abs(vel) > minvel then --It will become an absolute value.
            debounce = true
            print("touched")
            wait(0.5)
            debounce = false

        end
    end
end)

1 comment

0

This is wrong as the vel variable wont change as you indexed it from the get to.

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