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

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

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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
0
Nice catch Roger111 347 — 3y
Ad
Log in to vote
0
Answered by
Roger111 347 Moderation Voter
3 years ago
Edited 3 years ago

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
GetPropertyChangedSIgnal and .Changed doesn't fire when the velocity changes. Nickuhhhhhhhhhhhhhhh 834 — 3y
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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!

Answer this question