I Am Helping A Friend Make A Game That Has Requires A Sliding System, And I Have No Idea How To Make That. I Would Be Glad To Get A Script But It’s Okay If You Just Give An Explanation. The Player Would Slide For 2 seconds before having a 2.5 second cooldown, With An Animation, But Only Works When They Are Walking.
Heres A Picture Of Where The Player Needs To Slide
Are they supposed to slide while walkin on the wall, or off the treetops?
Could you just make the Part’s Friction low so they slide off?
If you mean like a run and slide system try searching the forums. I’ve seen a few posts about it. Try using the term “slide script” in the Search tool up top.
You’ll need to use ContextActionService or UserInputService to know when they press Control.
From there you need a function that plays the animation and if you want the movement to seem cool you’ll need to use a VectorForce to push them foward and you could use TweenService to slowly turn the force off
i tried this and it kinda works, i dont have any more ideas how to fix it. Maybe you can help?
Server Script :
local Player: Player = game.Players.PlayerAdded:Wait()
local Character = Player.CharacterAdded:Wait()
local Humanoid: Humanoid = Character:FindFirstChild("Humanoid")
local force = Instance.new("VectorForce")
local att0 = Instance.new("Attachment")
local SlideAnim = Humanoid:LoadAnimation(script.SlideAnimation)
att0.Parent = Character.PrimaryPart
force.Attachment0 = att0
force.Parent = Character.PrimaryPart
force.Force = Character.PrimaryPart.CFrame.LookVector * 0
force.ApplyAtCenterOfMass = true
force.RelativeTo = Enum.ActuatorRelativeTo.World
local CanUse = true
local ForceTween = game:GetService("TweenService"):Create(force, TweenInfo.new(2), {Force = Character.PrimaryPart.CFrame.LookVector * 0})
local function Slide()
if CanUse == true then
Humanoid.Running:Connect(function(speed)
if speed > 10 then
CanUse = false
SlideAnim:Play()
Humanoid.WalkSpeed = 0
force.Force = Character.PrimaryPart.CFrame.LookVector * 12000
ForceTween:Play()
task.wait(2)
SlideAnim:Stop()
Humanoid.WalkSpeed = 16
task.wait(2.5)
CanUse = true
end
end)
end
end
game:GetService("ReplicatedStorage").Slide.OnServerEvent:Connect(Slide)
Client Script :
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input:InputObject, gameProcessedEvent:boolean)
if gameProcessedEvent then
return
end
if input.KeyCode == Enum.KeyCode.LeftControl then
game:GetService("ReplicatedStorage").Slide:FireServer()
end
end)
The Problem Is That It Keeps Sliding Even When I Dont Press Left Control, It Just Repeats.
As far as your picture description goes, there is nothing there that suggested you wanted the player to slide under the log. Just remember that we can’t read your mind, you have to explain things in detail.
I wrote this quick slide, it isn’t a ‘complete’ slide because it doesn’t support slopes, but it works really well on flat surfaces. If you want to use it on your game, makes sure to disconnect the events and unbind the context action service to prevent memory leaks.
Works for R6 and R15.
Here’s the code:
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local slideKeybind = Enum.KeyCode.C
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
local animator = humanoid:WaitForChild("Animator")
local head = character:WaitForChild("Head") :: BasePart
local basePart = humanoid.RootPart
--local slideDuration = 1
local sliding = false
local fakeAccel = 1
local slideDistance = 60
local dynamicSlideDistance = slideDistance
local originalHipHeight = humanoid.HipHeight
local slideTrack = animator:LoadAnimation(script:WaitForChild("Animation"))
slideTrack.Looped = true
slideTrack.Priority = Enum.AnimationPriority.Action
local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
params.FilterType = Enum.RaycastFilterType.Exclude
params.IgnoreWater = true
local lastStep = Vector3.zero
local function enterSlide()
sliding = true
humanoid.AutoRotate = false
--humanoid.HipHeight = 0
-- must be set before updating walkspeed to 0
dynamicSlideDistance = slideDistance + humanoid.WalkSpeed * 1.2 -- so if you're running you slide further
fakeAccel = dynamicSlideDistance / 2
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
humanoid.JumpHeight = 0
humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
slideTrack:Play()
end
local function leaveSlide()
sliding = false
humanoid.AutoRotate = true
humanoid.HipHeight = originalHipHeight
humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed
humanoid.JumpPower = game.StarterPlayer.CharacterJumpPower
humanoid.JumpHeight = game.StarterPlayer.CharacterJumpHeight
dynamicSlideDistance = slideDistance
slideTrack:Stop()
end
local earlierTime = 0
local cooldownTime = 2
local function canSlide()
local timeNow = os.clock()
-- the cooldown
if timeNow < earlierTime then
return false
end
if not humanoid or humanoid.Health <= 0 then
return false
end
if humanoid.FloorMaterial == Enum.Material.Air then
return false
end
-- to prevent them from using 'slide' if they are not moving
if humanoid.MoveDirection == Vector3.zero then
return false
end
earlierTime = timeNow + cooldownTime
return true
end
local function slide(_, state: Enum.UserInputState, input: InputObject)
if not canSlide() then return end
if state == Enum.UserInputState.Begin then
enterSlide()
end
end
local function updateSlide(dt: number)
if not sliding then return end
local ray = workspace:Raycast((head.CFrame * CFrame.new(0, -1, 0)).Position, head.CFrame.LookVector * 2, params)
if fakeAccel < 0.8 and ray ~= nil then
leaveSlide()
end
fakeAccel = math.clamp(fakeAccel - 0.005, 0, 1)
if fakeAccel == 0 then
leaveSlide()
end
basePart:ApplyImpulse(basePart.CFrame.UpVector * -100)
local goal = basePart.AssemblyLinearVelocity:Lerp(basePart.CFrame.LookVector * dynamicSlideDistance, fakeAccel)
if goal ~= goal then
return
end
basePart.AssemblyLinearVelocity = goal
end
ContextActionService:BindAction("slide", slide, true, slideKeybind)
RunService.RenderStepped:Connect(updateSlide)
its amazing! but its not really what i’m looking for. like sure it has the slide duration. but i cant make it so the player has to be moving for it to work and i cant figure out how to make a cooldown for each slide usage.
That’s precisely why I added the canSlide() function because I thought you’d want cooldown and maybe something, so all you have to do is to change it up slightly.
It seems that the code I wrote for you, is indeed what you were looking for, so if you don’t mind marking it as a solution, i’d appreciate it.
local earlierTime = 0
local cooldownTime = 2
local function canSlide()
local timeNow = os.clock()
-- the cooldown
if timeNow < earlierTime then
return false
end
if not humanoid or humanoid.Health <= 0 then
return false
end
if humanoid.FloorMaterial == Enum.Material.Air then
return false
end
-- to prevent them from using 'slide' if they are not moving
if humanoid.MoveDirection == Vector3.zero then
return false
end
earlierTime = timeNow + cooldownTime
return true
end