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

So when i run my roll script it works. But when I jump and use it sends the plr flying?

Can someone help me?

all the code is in a local script and is put in the starter character scripts.

local UIS = game:GetService('UserInputService')
local Anim = game.StarterPack.ClassicSword:WaitForChild('RollAnim')
local plr = game.Players.LocalPlayer.Character
local cooldown = false

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R and cooldown == false then
		local Animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(Anim)
		Animation:Play()
		plr.HumanoidRootPart.Velocity += plr.HumanoidRootPart.CFrame.lookVector*150
		cooldown = true
		wait(.7)
		cooldown = false

	end

end)

https://gfycat.com/merryultimateegret the link is for the video

1 answer

Try using Humanoid:MoveTo. Usually, it walks to the place you input but you have a "Roll" animation overwriting that.

local UIS = game:GetService('UserInputService")
local CAS = game:GetService("ContextActionService")
local Anim = game.StarterPack.ClassicSword:WaitForChild('RollAnim')
local plr = game.Players.LocalPlayer
local char = plr.Character
local cooldown = false
local targetArea, previousSpeed

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R and not cooldown then
		cooldown = true
		local Animation = Char.Humanoid:LoadAnimation(Anim)
		Animation:Play()
		previousSpeed = Char.Humanoid.WalkSpeed -- Get previous speed
		Char.Humanoid.WalkSpeed = 150/Animation.Length -- Set speed
		targetArea = Vector3.new(Char.HumanoidRootPart.CFrame.lookVector.X*150, Char.HumanoidRootPart.CFrame.lookVector.Y*150, Char.HumanoidRootPart.CFrame.lookVector.Z*150) -- Set target area
		Char.Humanoid:MoveTo(targetArea) -- MOVE MOVE MOVE
		ContextActionService:BindAction( -- Freeze player
			"freezeMovement",
			function() return Enum.ContextActionResult.Sink end,
			false,
			unpack(Enum.PlayerActions:GetEnumItems())
		)
		Char.Humanoid.MoveToFinished:Connect(function(reached) -- Wait until finished
			Char.Humanoid.WalkSpeed = previousSpeed  -- Set to previous speed
			ContextActionService:UnbindAction("freezeMovement") -- Unfreeze player
		end)
		wait(.7)
		cooldown = false
	end
end)

You can see the comments for an explanation

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