How should I go about doing this?

So, I have a falling piano. If it falls on any players, they will be ragdolled, though I’m not sure how I should go about this.

I thought about using touched events, but I heard it isn’t reliable, so it should be avoided. Raycasts also came up, although I’m not sure how I’d go about doing that either.

Another issue is, if two players were under the piano and the touched event stopped after one of the players touched the piano, how would both be ragdolled if I were to disconnect the touched event to save memory?

So, what should I do? Are there any other alternatives?

Here’s how i’d do it:

Make an invisible part in the player’s character when he joins (or resets), weld it to the players humanoidrootpart, make it a reasonable height (probably as tall as the player), name it “RagdollHitbox” (personal preference), and use GetPartsInPart on the piano in a heartbeat/renderstepped event, if the part named RagdollHitbox is between the returned parts, then ragdoll the player.

Alternatively, you can skip the whole Hitbox part, and just use GetPartsInPart and check if hit.Parent has a Humanoid (like you would in a touched event), if it does, then a player touched it. I prefer the first method tho (personal preference)

I wouldn’t entirely recommend raycasts because you can only cast a ray down from one single point, a piano is big and you’d have to find a way to cover the entire surface of the piano.

1 Like

I would suggest using touched events for this. Although touched events can be unreliable sometimes, they are generally consistent with larger parts, such as a piano and a player.

For your case I would connect the touched event when the piano starts falling and disconnect it when it stops falling (AssemblyLinearVelocity is close to zero). This way you could ragdoll multiple players while still disconnecting the connection.

Considering I’m making a big game with much more weapons than just this piano, I won’t do that just for one weapon.

This doesn’t sound bad on paper, but the piano will collide with objects, and players won’t be inside, so I don’t see this working either.

True.

This doesn’t sound like much of a bad idea, although I’m not too certain about how close to zero I’d be checking. I’ll have to test this in practice to see if it’s any effective.

Could you elaborate on this? I’m not completely sure what you mean by that. If the piano will collide with other objects, and doesn’t fall on the player, then it shouldn’t ragdoll the player, correct me if im wrong tho.

I should’ve worded that better.

What I’m saying is that the piano has a collision, and by looking at the function name, it seems like it checks for parts inside of parts, but the players won’t be inside of the piano because it has a collision.

Although, I think I’m wrong about this.

GetPartsInPart should return parts that are touching it too, as far as i know.

Looking back at it, my first method would have still worked better, because that with CanCollide off would definitely be inside the piano, making it detect it. But i think it should still work without the hitbox part, you just gotta try it and see!

Judging from the Roblox API, I doubt it.

This method can be used in place of BasePart:GetTouchingParts() and is generally a better choice.

1 Like

Dang, that’s a bit strange… But thanks for bringing it up, I glossed over that. :sweat_smile:

Another thing I forgot to say is, how could I check this from a specific normal? I don’t want players that slightly brush the side of the piano to be ragdolled.

Make the Hitbox smaller? Idk what you mean.

You are completely missing my point. The hitbox is the piano, I can make the piano smaller, but this isn’t what I’m trying to do. Normal, as in different normal id’s.

You could always try creating an invisible part inside of the piano model that is slightly smaller than the piano itself. Then make it so that the part you added causes the players to ragdoll instead of the piano. This should stop players who touch the piano from being ragdolled, but ragdoll the players that it falls onto.

1 Like

True but I feel as if it would be more logical to just utilize normals in such a way that allows me to detect everything touched under the piano. I just like to script that way. :grin:

Get the lookvector between the hitpart and the piano’s center and check if it’s within a certain angle of the normal.

I always try to avoid the .touched event. For this scenario, I’d rely on distance checking.
After the object has reached a static point, or just hit the ground, check which players are close enough to account for their damage.

To be fair, I can’t say with confidence if this method rules over other methods mentioned in this post, performance, detection or otherwise. However, I do know that you won’t have to worry about the unfortunate unreliability of .touched, or the problem of detecting one thing for raycasting.

Dude you’re overthinking this. If the thing you’re looking for is the HumanoidRootPart, it’s impossible for it to “slightly brush the side” if you size the Piano hitbox correctly. My advice is to implement the system and test it out, and from there you can reach a conclusion.

1 Like

Make an invisible hit box part that is slightly smaller than the piano, and have it attached to the piano.
Use a .touched event on that hit box, and check for it hitting a player’s HumanoidRootPart.

For bonus points, you can also check the velocity of the hit box to see if the piano is just sitting there, or if its falling.

I’m detecting any part from the body, not just the HumanoidRootPart… And even so, I still only want it to account for parts under the piano