Bodyforce Question

Hello!

I’m currently scripting a system that allows users to skate for a group my friend is making. I was wondering why you can only go a certain speed.

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Player.CharacterAdded:wait()
Character = Player.Character
Torso = Character:WaitForChild("Torso")
LL = Character:WaitForChild("Left Leg")
RL = Character:WaitForChild("Right Leg")
Humanoid = Character:WaitForChild("Humanoid")
Tool = script.Parent
Anim = Tool:WaitForChild("Anim")
Anim.Parent = Character
wait()
AnimTrack = Humanoid:LoadAnimation(Anim)
Anim.Parent = Tool
Activated = nil
BodyForce = nil
Velocity = 0
Force = 950
function Weld(Part, C0)
end
Tool.Selected:connect(function()
    BodyForce = Instance.new("BodyForce", Torso)
    Activated = true
end)
Tool.Deselected:connect(function()
    Activated = nil
    AnimTrack:Stop()
    BodyForce:remove()
    print("Removed")
end)
Torso.Parent.Humanoid.Running:connect(function(SpeedyGnome)
    while SpeedyGnome > 1.3 do
        wait()
        if Activated then
            local Ray = Ray.new(Torso.Position, Vector3.new(0, -5, 0))
            local Hit = game.Workspace:FindPartOnRay(Ray, Character)
            if Hit == nil or Hit.Material ~= Enum.Material.Ice then
                BodyForce.Force = Vector3.new(0, 0, 0)
                if AnimTrack.IsPlaying then
                    AnimTrack:Stop()
                end
            else
                BodyForce.Force = Torso.CFrame.lookVector * Torso:GetMass() * Force
                if AnimTrack.IsPlaying == false then
                    AnimTrack:Play(0, 1, 3 - Torso.Velocity.magnitude * 0.04)
                end
            end
        elseif Activated == false then
            BodyForce.Force = BodyForce.Force * 0.99
        end
    end
end)

Here is a gif of it in action (you’ll notice how you can only go a certain speed)
https://gyazo.com/c9cd016f1b843c1552edc46d604e19ac.gf

1 Like

image

These are the lines that set the Force property. As you can see, only the last assignment sets it to something non-constant. The first two are constant assignments, they will always set the Force property to the same number assuming Torso:GetMass() doesn’t change. There’s no logic here to smoothly increase the Force, it just instantly goes to full force.

1 Like

Please learn to indent you code.

1 Like

It’s indented, take a closer look. It’s maybe missing some whitespace to make it easier to read, that’s all. Please be specific when providing feedback.

The answer was solved thanks to you.

When I first came on this post it wasn’t indented ( to me at least ).

My feedback was specific though, it was to indent. But that’s not needed now.

Makes sense! Now I cannot increase the mass of the torso (obv.) so how would you recommend going about this?