I want LinearVelocity when a key has been held by a user, so I have 2 scripts, one, which adds linear velocity to the character when InputBegan, and another which destroys it when InputEnded.
I have made a script that will change the velocity depending on the character CFrames (needs improvement, accepting suggestions)
This is a loop in a server (might be inefficient, accepting suggestions), and I want the loop to end when the LinearVelocity has been destroyed by another script.
I tested this by putting print(), but it seems like the loop is still running because it is still printing.
How can I end the loop when LinearVelocity has been destroyed?
Thanks!
game.ReplicatedStorage.add.OnServerEvent:Connect(function(p)
local char = p.Character or p.CharacterAdded:Wait()
local HRP = char.HumanoidRootPart
local veloc = Instance.new("LinearVelocity",char)
veloc.Attachment0 = char.HumanoidRootPart.RootRigAttachment
veloc.MaxForce = 5000
while veloc do
veloc.VectorVelocity = (char:GetPivot().LookVector*10 + char:GetPivot().UpVector)*10
print("a")
task.wait(0.1)
end
end)```