For some reason the deceleration is not working. so when player stops pressing the arrow key he doesn't slide :(
local PlayerVelocity = script.Parent:WaitForChild("PlayerVelocity")
local PlayerMovementValue = script.Parent:WaitForChild("PlayerMovementValue")
local uis = game:GetService("UserInputService")
--Whenever player is moving, MovementValue is equal to 1.
--Whenever player is _not_ moving, MovementValue is equal to 0.
uis.InputBegan:connect(function(input,gp)
if input.KeyCode == Enum.KeyCode.Left then
--[[Accelerating:]]
while PlayerMovementValue.Value == 1 do
wait()
if (PlayerVelocity.Value < 0) then
PlayerVelocity.Value = (PlayerVelocity.Value + 0.5)*PlayerMovementValue.Value
elseif (PlayerVelocity.Value < 3) then
PlayerVelocity.Value = (PlayerVelocity.Value + 0.046875)*PlayerMovementValue.Value
else
--[Decelerating]]
PlayerVelocity.Value = PlayerVelocity.Value -math.min(math.abs(PlayerVelocity.Value),0.046875)
*math.sign(PlayerVelocity.Value)
end
end
end
end)
