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?
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?
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.
"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.
ah, apologies, edited
You also don't necessarily need to reference the HRP. The Humanoid Object already contains a pointer to the BasePart: Humanoid.RootPart.
Thank you.
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.
1 comment
Yes try adding velocity to the Y axis.