Slide script keys

My script:
local UIS = game:GetService(“UserInputService”)
local char = script.Parent
local slideAnim = Instance.new(“Animation”)

slideAnim.AnimationId = “https://www.roblox.com/assets/?id=9415043023

local keybind = Enum.KeyCode.C
local canslide = true

UIS.InputBegan:Connect(function(input,gameprocessed)
if gameprocessed then return end
if not canslide then return end

if input.KeyCode == keybind then
canslide = false

local playAnim = char.Humanoid:LoadAnimation(slideAnim)
playAnim:Play()


local slide = Instance.new("BodyVelocity")
slide.MaxForce = Vector3.new(1,0,1) * 30000
slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
slide.Parent = char.HumanoidRootPart

for count = 1, 8 do
  wait(.1)
  slide.Velocity *= .7
end
playAnim:Stop()
slide:Destroy()
canslide = true

end
end)

I was wondering if someone can add something to this. What I need is that the Player has to be holding down W+Shift and moving for the slide to work if I press W+Shift and not moving the animation won’t play

This would really help if someone could do this for me thanks

1 Like

What you want to do is check if Shift is pressed. You can use UserInputService for this. Once you get a .InputBegan containing Shift you can store that is down. If it is down, then while pressing W you play the animation.

Since this requires that both W and Shift is held down it means the character will be moving, so you don’t need to make sure it is moving. What you need next is to register when Shift and W is let go, you can do this using .InputEnded.

Can edit this script I put to do that bc idk how to

I’d recommend starting with a smaller task. If you still can’t complete it then I can help you, but I’d rather just guide you than give you the code.

Try making a script to keep track off if W is being held down.

Tip 1:

By using .InputBegan you can check if W is being pressed.

Tip 2:

By creating a variable called w_down and setting it to true when it is pressed you can keep track of it being pressed.

Tip 3:

Use what you learned on .InputEnded

Once this is done, you can do the same for Shift. When this is done you are more or less done with your code!

I don’t wanna sound rude but I rlly don’t know anything about scripting so can I please have the script srry that I sound rude

1 Like

He isn’t on right now But, I’ll give you the basics of the function you will have to write the script for the animations

local UIS = game:GetService("UserInputService") -- Here We are getting the UserInputService, This detects if the Player pressed a key such as W,S,D 


UIS.InputBegan:Connect(function(Input) -- The Player pressed a Key
	if Input.KeyCode == Enum.KeyCode.W and Enum.KeyCode.LeftShift then -- Here We check if the Key is W & Shift
		-- The player has pressed/ is holding the W And leftShift key Do your Slide animation
	end
end)

UIS.InputEnded:Connect(function(Input) -- The Player stopped holding/Pressing the key
	if Input.KeyCode == Enum.KeyCode.W and Enum.KeyCode.LeftShift then -- We Check if the Keys are W & LeftShift 
		-- The Player stopped Holding W and the LeftShift key Stop the Slide animation
	end
end)
3 Likes