Hey, I’ve been trying to make a movement system but i have a little problem.
Sometimes it goes into the right position, and sometimes it doesn’t.
Here’s an example: https://youtu.be/k4lQppS3Ets
CODE:
local module = {}
local Debris = game:GetService("Debris")
local frDash = Instance.new("Animation")
frDash.AnimationId = "http://www.roblox.com/asset/?id=xxx"
local rDash = Instance.new("Animation")
rDash.AnimationId = "http://www.roblox.com/asset/?id=xxx"
local lDash = Instance.new("Animation")
lDash.AnimationId = "http://www.roblox.com/asset/?id=xxx"
local bDash = Instance.new("Animation")
bDash.AnimationId = "http://www.roblox.com/asset/?id=xxx"
function module.Dash(player, dashType)
local anim
local character = player.Character
local humanoid = character.Humanoid
local att0 = Instance.new("Attachment", character.HumanoidRootPart)
att0.Parent = character.HumanoidRootPart
local linearVelocity = Instance.new("LinearVelocity", character.HumanoidRootPart)
linearVelocity.Attachment0 = att0
linearVelocity.MaxForce = 100000
linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
local dashDuration = 0.33
local dashSpeed = 100
if dashType == "A" then
print(dashType)
anim = humanoid.Animator:LoadAnimation(lDash)
anim.Priority = Enum.AnimationPriority.Action
anim:Play()
linearVelocity.VectorVelocity = -(character.HumanoidRootPart.CFrame.RightVector) * dashSpeed
elseif dashType == "D" then
anim = humanoid.Animator:LoadAnimation(rDash)
anim.Priority = Enum.AnimationPriority.Action
anim:Play()
linearVelocity.VectorVelocity = character.HumanoidRootPart.CFrame.RightVector * dashSpeed
elseif dashType == "W" then
anim = humanoid.Animator:LoadAnimation(frDash)
anim.Priority = Enum.AnimationPriority.Action
anim:Play()
linearVelocity.VectorVelocity = character.HumanoidRootPart.CFrame.LookVector * dashSpeed
elseif dashType == "S" then
anim = humanoid.Animator:LoadAnimation(bDash)
anim.Priority = Enum.AnimationPriority.Action
anim:Play()
linearVelocity.VectorVelocity = -(character.HumanoidRootPart.CFrame.LookVector) * dashSpeed
end
Debris:AddItem(att0, dashDuration)
Debris:AddItem(linearVelocity, dashDuration)
end
return module