How would you detect how fast an object was moving after it was touched?

I want to create a versatile ragdoll script with things such as gibs, limb health, and limited quantities of blood before you bleed out. I also want to add a general way to deal damage to the play and limbs when a part hits it while going fast enough. thank you.

I believe this script should work for detecting how fast a part is moving after being touched with physics-based movements.

Part.Touched:Connect(function()
    print(Part.Velocity)
end)

BasePart.Velocity is deprecated by ROBLOX, not a great idea to use it.

Depends on how the part is hitting the player. Are you planning on using Constraints? Then you can use the constraint properties to determine the velocity.

Are you using manual CFrame calculations? Then you can use physics formulas to determine the velocity.

--may not be very realistic at times
local MIN_DAMAGE_FORCE = 120

--just set this to humanoidrootpart position
--when player has just stopped touching the ground
--HumanoidState == Jumping or HumanoidState == Freefall
--only set on state changed
local AirbornStart = Vector3.zero

--no need to make more than one touched connection because
--humanoid.Touched gives both parts
local TouchedConnection = Humanoid.Touched:Connect(function(HitPart, CharacterPart)
    --required for force calculation
    local TravelledDistance = (AirbornStart - Character.PrimaryPart.Position).Magnitude
    
    --Calc credit @Dav_itt
    --https://devforum.roblox.com/t/--/1021305/4?u=judgy_oreo
    local Force = CharacterPart.Mass * CharacterPart.AssemblyLinearVelocity.Magnitude^2 / (2 * TravelledDistance)
    --can be used for fine-tuning
    print("Impact force:", Force)
    --is the impact force big enough for the player to take *any* damage?
    if Force > MIN_DAMAGE_FORCE then
        --Ragdoll or whatever
    end
end)
1 Like

i dont think people give a crap about deprecated stuff as long as it still works i say go ahead do it

I met some guy who thought Roblox was super laggy because they were using Mouse.KeyDown.

It has a 0.1 second delay compared to UserInputService. You shouldn’t use deprecated stuff because they can break or stop working to the point where it could make your whole game unplayable, and Roblox won’t fix it. Region3s were broken for a while just after they were deprecated, and I highly doubt the fact that they started working again randomly was intentional.

1 Like

i forgor what mouse.KeyDown was? is it like mouse.hit.p if so very ez fix

No, it’s basically just UserInputService’s InputBegan, but worse because it’s under Mouse.

Nevertheless, you shouldn’t use deprecated stuff because they won’t get fixed when they inevitably break.

https://developer.roblox.com/en-us/api-reference/property/BasePart/AssemblyLinearVelocity

Although for the most part this usually returns a similar value to ‘Velocity’.

would that system work for also detecting when the player hits something at a high speed? or only a part hitting the player?