To preface, I am a new scripting.
I am trying to make a lot of movement actions in my game but they only work if I apply a linear velocity. While this linear velocity is being applied it does not update on the server correctly.
local MovementSent = game.ReplicatedStorage.MovementSent
local MovementConfirmed = game.ReplicatedStorage.MoveConfirmed
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local IsDashing = Instance.new("StringValue", char)
IsDashing.Name = "IsDashing"
IsDashing.Value = "NotDashing"
end)
end)
MovementSent.OnServerEvent:Connect(function(plr, eventType)
local char = plr.Character
local hum = char.Humanoid
local HRP = char.HumanoidRootPart
local dashForce = 150
local dashCD = 1
local function dashSound() --sound
local dashSound = Instance.new("Sound", HRP)
dashSound.Name = "dashSound"
dashSound.SoundId = "rbxassetid://7273189708"
dashSound.PlaybackSpeed = 2
dashSound.Playing = true
task.wait(dashSound.TimeLength)
dashSound:Destroy()
end
if eventType == "Dash" and char.IsDashing.Value == "NotDashing" then
char.IsDashing.Value = "Dashing"
local anim = char.Humanoid:LoadAnimation(script.Dash)
anim:Play(0)
local debugAtt = Instance.new("Attachment", HRP) --the buggy linearvelocity stuff i had to do
debugAtt.Name = "UDA"
local debugLV = Instance.new("LinearVelocity", HRP)
debugLV.Attachment0 = debugAtt
debugLV.RelativeTo = "Attachment0"
debugLV.MaxForce = 0
coroutine.wrap(dashSound)()
HRP.AssemblyLinearVelocity = HRP.CFrame.LookVector * Vector3.new(1,0,1) * dashForce -- the actual dash
MovementConfirmed:FireAllClients(plr, "Dash")
debugLV:Destroy()
debugAtt:Destroy()
task.wait(dashCD)
if char.IsDashing.Value == "Dashing" then
char.IsDashing.Value = "NotDashing"
end
end
end)