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

How could I fling an object with a script?

I have created a script that makes the player ragdoll when they die, but I want to make the player fling away from the person who killed them.

My question is how do you fling an object? Does it have anything to do with velocity?

1 comment

0

Yes try adding velocity to the Y axis.

1 answer

✓ Accepted answer

Yes, Body Velocity.

More information here: https://developer.roblox.com/en-us/api-reference/class/BodyVelocity

Anyways, here the code with comments as an explanation, if you have any questions, please comment!

game.Players.PlayerAdded:Connect(
    function(plr)
        plr.CharacterAdded:Connect(
            function(Character)
                    

                    local Humanoid = Character:FindFirstChild("Humanoid") -- Humanoid
                   if Humanoid.Health = 0 then -- If the player is dead

                    local BodyVelocity = Instance.new("BodyVelocity") -- Creates a new BodyVelocity force inside Character
BodyVelocity.Parent = Character

                    BodyVelocity.Velocity = Vector3.new(0, 200, 0) -- Sets velocity, you can change this up depending on what direction you want the player to go to in.

                    wait(1)

                    BodyVelocity:Destroy() -- Deletes the force, making the player start to come back down.
                end
            end
        )
    end
)

Please accept answer if it works so we both get reputation.

5 comments

0

"touch" is undefined, no Touched event is present. The CharacterAdded signal supplies the Model already, referencing it's parent will point to workspace; the HumanoidRootPart allocation is invalid. The second argument to the Instance constructor was deprecated, it's parent should always be set after properties are assigned. 

0

ah, apologies, edited

0

You also don't necessarily need to reference the HRP. The Humanoid Object already contains a pointer to the BasePart: Humanoid.RootPart.

0

Thank you.

0

Looking at this now, It gives me an error when using the script

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