I’m making a system that allows a player to slide, however the animation behind the system does not work well on players (whether idle or moving). I’ve tried: Changing animation priority, changing animation weight, changing animations, playing animation on server and on client.
local Crosshair = require(script.DynamicCrosshair).New(script.Parent.CrosshairContainer,10,18)
Crosshair:Enable()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local weaponsManager = require(ReplicatedStorage.Libraries.WeaponsManager)
local UIS = game:GetService("UserInputService")
local mouseDown = false
local isCrouching = false
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local isSliding = false
local humanoid : Humanoid = char:FindFirstChild("Humanoid")
local slideTrack = char:FindFirstChild("Animator",true):LoadAnimation(game.ReplicatedStorage.Effects.SharedAnims.Slide)
slideTrack.Priority = Enum.AnimationPriority.Action
local slideDuration = 1
local slideSpeed = 50
local function startSlide()
if isSliding or humanoid:GetState() ~= Enum.HumanoidStateType.Running then
return
end
isSliding = true
slideTrack:Play()
char.Humanoid:SetAttribute("sliding",true)
game.ReplicatedStorage.Remotes.SlideStateUpdate:FireServer(true)
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = char.HumanoidRootPart.CFrame.LookVector * slideSpeed
bodyVelocity.MaxForce = Vector3.new(100000, 0, 100000)
bodyVelocity.Parent = char.HumanoidRootPart
local listener = humanoid.Jumping:Once(function(active)
if active then
bodyVelocity:Destroy()
isSliding = false
char.Animate.AnimatorFrozen.Value = false
slideTrack:Stop()
game.ReplicatedStorage.Remotes.SlideStateUpdate:FireServer(false)
char.Humanoid:SetAttribute("sliding",false)
end
end)
task.delay(slideDuration, function()
if isSliding then
listener:Disconnect()
bodyVelocity:Destroy()
isSliding = false
slideTrack:Stop()
game.ReplicatedStorage.Remotes.SlideStateUpdate:FireServer(false)
char.Humanoid:SetAttribute("sliding",false)
end
end)
end
local isSprinting = false
UIS.InputBegan:Connect(function(input,proc)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
-- code not needed for post
end
if input.KeyCode == Enum.KeyCode.LeftShift then
isSprinting = true
end
if input.KeyCode == Enum.KeyCode.R then
weaponsManager:requestReload()
end
if input.KeyCode == Enum.KeyCode.LeftControl or input.KeyCode == Enum.KeyCode.C then
print(isSprinting)
if humanoid.MoveDirection ~= Vector3.zero and isSprinting and not isSliding and not isCrouching then
startSlide()
else
if isSliding then
return
end
isCrouching = not isCrouching
weaponsManager.crouch(isCrouching)
end
end
end)
-- some code is removed as it isnt relevant to the issue (probably)
-- server handling
Remotes.SlideStateUpdate.OnServerEvent:Connect(function(plr,isSliding)
for i,v in pairs(plr.Character:FindFirstChild("Animator",true):GetPlayingAnimationTracks()) do
v:Stop()
end
local playerAnimations = existsInAnimationList(plr.Character)
if playerAnimations then
playerAnimations.animations.idle:Play()
end
plr.Character.Humanoid.HipHeight = if isSliding then 1 else 2
end)
If I’m missing anything or more context is needed let me know.