The reason your code is simply teleporting you is because you are setting the HumanoidRootPart's CFrame rather than transitioning the CFrame/position.
While you may be able to accomplish the desired result using tweens, I would not recommend it.
The method I would recommend is using BodyPositions and BodyGyros.
This is the way I accomplished a 'dash' effect:
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local speed = 20
local total_add = 30
local dampener = 3
local direction = nil
local bPos
local bGyro
local count = 0
local dashDebounce = false
local Player = game.Players.LocalPlayer
local char = Player.Character
repeat
char = Player.Character
wait()
until char ~= nil
local HRP = char:WaitForChild("HumanoidRootPart")
local humanoid = char.Humanoid
local function Setup()
HRP = char:WaitForChild("HumanoidRootPart")
direction = Vector3.new(humanoid.MoveDirection.X * speed / dampener, 0, humanoid.MoveDirection.Z * speed / dampener)
bPos = Instance.new("BodyPosition")
bPos.Position = HRP.Position
bPos.Parent = HRP
bGyro = Instance.new("BodyGyro")
bGyro.CFrame = HRP.CFrame
bGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
bGyro.Parent = HRP
humanoid.PlatformStand = true
end
local function Stop()
bPos:Destroy()
bGyro:Destroy()
humanoid.PlatformStand = false
end
UIS.InputBegan:Connect(function(input,gpe)
if not gpe and not dashDebounce then
if input.KeyCode == Enum.KeyCode.Q then
Setup()
count = 0
dashDebounce = true
end
end
end)
humanoid.StateChanged:Connect(function(old,new)
if new == Enum.HumanoidStateType.Landed then
dashDebounce = false
end
end)
while wait(0.1) do
if dashDebounce then
if count < total_add then
local increment = speed / 10
if count + increment > total_add then
increment = (count + increment) - total_add
end
bPos.Position += Vector3.new(direction.X,increment,direction.Z)
count += speed / 10
bGyro.CFrame = CFrame.new(HRP.Position,Vector3.new(direction.X + HRP.Position.X,HRP.Position.Y,direction.Z + HRP.Position.Z))
else
Stop()
end
end
end
My general explanation of the code is this:
The player's vertical climb is speed studs per second.
The player's directional movement is equal to 1 / dampener * speed studs per second.
These variables can be altered to change the way the dash looks:
local speed = 20
local total_add = 30
local dampener = 3
If you want the player to move directly up with no directional movement, change
Pos.Position += Vector3.new(direction.X,increment,direction.Z)
count += speed / 10
bGyro.CFrame = CFrame.new(HRP.Position,Vector3.new(direction.X + HRP.Position.X,HRP.Position.Y,direction.Z + HRP.Position.Z))
to
Pos.Position += Vector3.new(0,increment,0)
count += speed / 10
bGyro.CFrame = HRP.CFrame
I would also highly recommend using an animation, because as it stands right now, the player looks stiff as a board (as a result of Humanoid.PlatformStand)
This may be confusing, and I completely get that. If you would like something explained in more detail, feel free to contact me on Discord (phxntxsmic#2021)
2 comments
You can use a BodyVelocity to do so. Set the Velocity to go up and remove the BodyVelocity when done.
Thanks but how would I add that to my scrip sorry am pretty new to scripting