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

How do I make a a script where if you go a high velocity, breakJoints is called on the part?

I really don't know how to reference the velocity in ROBLOX Lua coding. This is my block of code;

     if script.Parent.Velocity == 75 then
script.Parent:breakJoints()

end

I first thought that just saying "Velocity" was gonna work, but it doesn't. Any suggestions?

3 answers

✓ Accepted answer

The Velocity property of an Part returns a Vector3, you could convert the Vector3 to a float by getting the Magnitude of it.

local BREAK_VELOCITY = 10

if Part.Velocity.Magnitude >= BREAK_VELOCITY then
	Humanoid:BreakJoints()
end

1 comment

0

Nice catch

EDIT: Nevermind, you cannot use GetPropertyChangedSignal on velocity

ANSWER: You will use GetPropertyChangedSignal

Example:

local part -- This must be set to the primary part of the object you wish to check the velocity for
part:GetPropertyChangedSignal("Velocity"):Connect(function()
	if part.Velocity >= 75 then
		--break joints
	end
end)

1 comment

1

GetPropertyChangedSIgnal and .Changed doesn't fire when the velocity changes.

for convenience, we're going to make a variable for the max velocity, called "MAX" i also had this problem when i started,but i figured it out, there's a hidden value to "velocity" called magnitude that is pretty much the general speed (in SPS) that the part is moving at

we can add .Magnitude after Velocity to use that, which should make it work properly

local MAX = 75 -- the value at which the joints break

     if script.Parent.Velocity.Magnitude >= MAX then --checking if the speed of the part is greater or equal to max (using == might not work since sometimes the part can skip the target because its going too fast)
     script.Parent:breakJoints() -- breaking the joints in the part
end

hope this helped you out!

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