Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to move forward while performing animation?

So I'm very new to scripting, but I am trying to make a roll script where the player does a roll animation and moves forward, when a key is pressed. I got everything working except for the part where the player moves forward, I want it to be a fixed distance so the player can't interrupt it in anyway, and the player should roll in the direction that the player was already moving. So it's basically a Dark Souls roll. It would be amazing if someone could help me.

This is my code:

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()



local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=8182577095" 


local debounce = false
mouse.KeyDown:connect(function(key)
	if key == "q" and not debounce then
		debounce = true
		
		local playAnim = humanoid:LoadAnimation(anim)
		playAnim:Play()
		
		
		wait(1)
		debounce = false
end




end)

1 answer

✓ Accepted answer

Mouse.KeyDown was superseded. You should instead use UserInputService.

On InputBegan, you could get the player's root part, and give it a velocity depending on its LookVector.

UserInputService.InputBegan:Connect(function(input, typing)
	local Root = player.Character.HumanoidRootPart -- get the HumanoidRootPart
	if not typing and input.KeyCode == Enum.KeyCode.Q then -- check if the player pressed Q
		Root.Velocity = Root.CFrame.LookVector * 200 -- apply a velocity
	end
end)

1 comment

0

Thanks for the help!

This discussion is preserved as it was. New answers, comments, and votes are closed.