Slide doesn't work properly

Got a slide script that just doesn’t wanna cooperate, like at all.

There are 2 major problems:

  1. You cannot turn during the slide, whether HumanoidRootPart is anchored or not.
  2. 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.

1 Like

This should fix the no turning issue.

function calculate_position(player, playerVelocity, deltaTime)
	local moveBy = playerVelocity * deltaTime
	player.Character.HumanoidRootPart.CFrame += moveBy
end
1 Like

Nuh uh, it just makes playerVelocity an invalid argument. (expected Vector3, got CFrame)

1 Like

Actually, ditch the plrVelocity variable and instead move the player like this:

player.Character.HumanoidRootPart.CFrame *= CFrame.new(0, 0, -slidespeed)

Ditched this method entirely and decided to go without any server sided scripts, it just slides in whatever direction the camera is facing, works just fine now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.