How do i make a player fling?

I posted a similar topic before, but I don’t really know where to start. Someone mentioned about changing velocity, could anyone give me some pointers on what I need to do, if I want to change the players velocity? Do I need do create a new instance about BodyVelocity and make it a child to the player? I have been stuck on this for ages, any help would be greatly appreciated as I am still in the learning stage of scripting.

10 Likes

I’d say use whatever you have at hand to make them move, like BodyVelocity and then set it to math.huuuuuge

1 Like

Just grab the players HumanoidRootPart located in the character then change its velocity using Vector3 values such as:

Vector3.new(math.huge, math.huge, 0) – random tho you can change it

and that should send them to absolute chaos, though you can decrease from math.huge since math.huge is just inf but worded differently…

the humanoidrootpart can be found like this:

local Player = game:GetService("Player")
local LPlr = Player.LocalPlayer
local Character = LPlr.Character
local HRP = Character:WaitForChild("HumanoidRootPart") -- Basically the humanoidrootpart

HRP.Velocity =  -- basically anything goes after this, make the velocity however u like

That code is done in local scripts however you can also do it on server if you get the character (depends really)

No need to use bodyvelocity when you already got a velocity property on the character, and if you want, you can activate platform stand/trip state on the character to make the fling even better.

3 Likes

Sorry, I am still learning, but is this how you do it?

script.Parent.Touched:Connect(function()

local Player = game:GetService("Player")

local LPlr = Player.LocalPlayer

local Character = LPlr.Character

local HRP = Character:WaitForChild("HumanoidRootPart") 

Vector3.new(25,25,0)

HRP.Velocity = 50

end)

Well, not entirely. Assuming that is in a server script, Player.LocalPlayer would be a nil value, as it can only be referenced from LocalScripts. Additionally, I would use :FindFirstChild() instead of :WaitForChild, as FindFirstChild would return nil if HRP does not exist, while :WaitForChild would return an infinite yield possible warning.

script.Parent.Touched:Connect(function(touch)

if touch.Parent:FindFirstChild("HumanoidRootPart") == nil then return end --Make sure HRP exists

local HRP = touch.Parent:FindFirstChild("HumanoidRootPart") -- HumanoidRootPart

local Humanoid = touch.Parent:FindFirstChild("Humanoid") -- Humanoid

Humanoid.Sit = true -- Makes the player sit

local BodyVelocity = Instance.new("BodyVelocity", HRP) -- Creates a new BodyVelocity force inside HRP

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)

(sorry for bad formatting on mobile)

15 Likes

No, no, no :doh: There is no ‘Player’ Service. A Touch Event always gives you one piece of information, namely the part which touched. If you got a character, it is always the parent of this part, as only the character’s parts can touch things. Next thing you do is trying to find the HRP. I think you understood how to do this.

After that you check for the existance of it and if it exists, you set it’s velocity to math.huge. It is basically the biggest value you could get and this lets the player fling.

script.Parent.Touched:Connect(function(Part)
    local Character = Part.Parent
    local HRP = Character:FindFirstChild("HumanoidRootPart")
    if HRP then -- touching part was part of a character
        local BodyVelocity = Instance.new("BodyVelocity",HRP) -- creates a new BodyVelocity 
        BodyVelocity.Velocity = Vector3.new(math.huge,math.huge,math.huge)  -- runs indefinetly
        HRP.Velocity = Vector3.new(math.huge,math.huge,math.huge)  -- runs once
    end
end)

If you only want the player to fling in one direction replace 2 of math.huge with 0 ,depending on which direction you want it to fling.

5 Likes

The velocity value in a BasePart is used to describe how the BasePart is actively changing. Setting the Velocity to a new Vector3 value would not apply the force to the HumanoidRootPart.

3 Likes

Isn’t the HRP also affecting the rest of the body and therefore let’s the whole character fling? Or did I read something wrong?

Ah got it

3 Likes

While I was testing changing it to a Vector3 value instead of using a BodyVelocity force, it didn’t apply the force to HumanoidRootPart. It reset back to 0 every time it was changed by the script. In this case, using a BodyVelocity force would be a more efficient way of doing it, as you have control not only of the actual velocity, but also MaxForce and P (Aggressiveness of the force).

3 Likes

I think it depends on how the fling should look like. Whether it should only fling once or indefinitely.

2 Likes

Yes. You would want to destroy the BodyVelocity force after a certain amount of time, which would stop the force being applied to the player and make them fall back to the ground.

Or, if you for some reason wanted them to fling indefinitely, you could not destroy the force at all.

4 Likes