This is a script inside of a remote event that gets activated by a localscript. The localscript doesn’t really matter.
Does anyone know how I can fix this?
local TweenService = game:GetService("TweenService")
script.Parent.OnServerEvent:Connect(function(player, action)
local character = player.Character
local root = character:WaitForChild("HumanoidRootPart")
local dashDuration = .5
local dashPower = 50
local info = TweenInfo.new(
dashDuration,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out
)
if action == "forward" then
local bv = Instance.new("BodyVelocity", root)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = root.CFrame.LookVector * dashPower
local tween = TweenService:Create(bv, info,{Velocity = Vector3.new(0,0,0)})
tween:Play()
tween.Completed:Connect(function()
bv:Destroy()
end)
elseif action == "backward" then
local bv = Instance.new("BodyVelocity", root)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = root.CFrame.LookVector * -dashPower
local tween1 = TweenService:Create(bv, info,{Velocity = Vector3.new(0,0,0)})
tween1:Play()
tween1.Completed:Connect(function()
bv:Destroy()
end)
elseif action == "left" then
local bv = Instance.new("BodyVelocity", root)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = root.CFrame.XVector * -dashPower
local tween2 = TweenService:Create(bv, info,{Velocity = Vector3.new(0,0,0)})
tween2:Play()
tween2.Completed:Connect(function()
bv:Destroy()
end)
elseif action == "right" then
local bv = Instance.new("BodyVelocity", root)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = root.CFrame.RightVector * dashPower
local tween3 = TweenService:Create(bv, info,{Velocity = Vector3.new(0,0,0)})
tween3:Play()
tween3.Completed:Connect(function()
bv:Destroy()
end)
end
end)