Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can I have some help in making my swimming script be more "stable"?

Asked by 6 years ago

My script parents BodyForces when you press space at a certain Y value or below it to create a swimming/flying effect. Only problem is that you "bounce" around a ton when you swim/fly.

my script:

local player = game.Players.LocalPlayer
local char = player.Character
local UpperTorso = char.UpperTorso
local UIS = game:GetService("UserInputService")
local SwimTop = -12.261
local SwimBottom = -155.228
local SwimDebounce = true
local Debounce = true

local function SwimUp()
    if Debounce then
        char.DoubleJumping.Disabled = true
        char.Evasion2.Disabled = true
        Debounce = false
        if UpperTorso:FindFirstChild("SwimForce") == nil then
            char.Humanoid.JumpPower = 0
            local BodyForce = Instance.new("BodyForce")
            BodyForce.Name = "SwimForce"
            BodyForce.Force = Vector3.new(0,3550,0)
            BodyForce.Parent = UpperTorso
            UpperTorso:FindFirstChild("SwimForce").Force = Vector3.new(0, 8550,0)
            wait(.1)
            UpperTorso:FindFirstChild("SwimForce").Force = Vector3.new(0, 4550,0)
        elseif UpperTorso:FindFirstChild("SwimForce") then
            UpperTorso:FindFirstChild("SwimForce").Force = Vector3.new(0, 8550,0)
            wait(.1)
            UpperTorso:FindFirstChild("SwimForce").Force = Vector3.new(0, 4550,0)
        end
    end
end

local function SwimDown()
    char.DoubleJumping.Disabled = true
    char.Evasion2.Disabled = true
    char.Humanoid.JumpPower = 0
    if UpperTorso:FindFirstChild("SwimForce") then
        UpperTorso:FindFirstChild("SwimForce").Force = Vector3.new(0, 1000,0)
        Debounce = true
        wait(.1)
        UpperTorso:FindFirstChild("SwimForce").Force = Vector3.new(0, 4000,0)
    end
end

local function Restore()
    char.Humanoid.JumpPower = 60
    for i, Forces in ipairs(char:GetDescendants()) do
        if Forces.Name == "SwimForce" then
            Forces:Destroy()
        end
    end
    char.DoubleJumping.Disabled = false
    char.Evasion2.Disabled = false
    Debounce = true
end



while wait() do
    if UIS:IsKeyDown(Enum.KeyCode.Space) and SwimDebounce then
        if UpperTorso.Position.Y < SwimTop then
            SwimUp()
        end
    elseif UpperTorso.Position.Y < SwimTop and SwimDebounce then 
        SwimDown()
    end
    if UpperTorso.Position.Y > -20.261 then
        SwimDebounce = false
        Restore()
    else
        SwimDebounce = true
    end
end

What it does right now:

https://gyazo.com/c7b476884f0bc54192e355d69c0bc51b

What I want it to look like:

https://gyazo.com/d73fe178e570639102f91b1667722df3

(A bit blurry, but that's cuz of the screen effect)

Answer this question