Got a slide script that just doesn’t wanna cooperate, like at all.
There are 2 major problems:
- You cannot turn during the slide, whether HumanoidRootPart is anchored or not.
- The player gets setback when the animation starts only when moving, if the player stands still and then triggers the slide, there’s no setback.
No setback version (player isn’t moving)
Setback version (player is walking)
There are 2 scripts for the entire slide, one client-side, and one server-side.
Code 1: Client-side
local event = game:GetService("ReplicatedStorage"):WaitForChild("SlideEvent")
local slidespeed = 36
local timer = 0.8
local UIS = game:GetService("UserInputService")
local plr = game:GetService("Players").LocalPlayer
local slideanim = script:WaitForChild("SlideAnim")
function beginSlide (input, gameProcessed)
local animator = plr.Character.Humanoid:FindFirstChildOfClass("Animator")
if plr.Character.Humanoid.WalkSpeed == 32 then
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftControl then
event:FireServer(slidespeed, timer)
local animtrack = animator:LoadAnimation(slideanim)
animtrack:Play()
game.StarterPlayer.StarterCharacterScripts.Sprint.Disabled = true
task.wait(timer)
game.StarterPlayer.StarterCharacterScripts.Sprint.Disabled = false
end
end
end
end
UIS.InputBegan:Connect(beginSlide)
And Code 2: Server-side
local event = game.ReplicatedStorage.SlideEvent
function calculate_position(player, playerVelocity, deltaTime)
local moveBy = playerVelocity * deltaTime
player.Character.HumanoidRootPart.Position += moveBy
end
event.OnServerEvent:Connect(function(player, slidespeed, timer)
player.Character.HumanoidRootPart.Anchored = true
local connection = nil
connection = game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
timer -= deltaTime
if timer <= 0 then
connection:Disconnect()
player.Character.HumanoidRootPart.Anchored = false
return
end
local plrVelocity = player.Character.HumanoidRootPart.CFrame.LookVector * slidespeed
calculate_position(player, plrVelocity, deltaTime)
end)
end)
I spent way too much time on this, it’s getting annoying now.