I’m trying to make a fly script for my game but during the tests, I encountered a problem that I can’t solve : linear velocity teleport the character to absurd position (like (100000000000,1000000000000,10000000000)
I tried debugging and looking on the web but found nothing to solve my strange problem.
here’s the script (not finished at all) :
local PlayerGui = game.Players:GetPlayerFromCharacter(script.Parent).PlayerGui
local Character = script.Parent
local UIS = game.UserInputService
local HRP = Character:WaitForChild("HumanoidRootPart")
local Button = PlayerGui.ScreenGui.Frame
local FlyEnabled = false
local Attachment = Instance.new("Attachment", HRP)
local LinearVelocity = Instance.new("LinearVelocity", HRP)
LinearVelocity.Attachment0 = Attachment
LinearVelocity.MaxForce = math.huge
LinearVelocity.Enabled = false
LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
game["Run Service"].Heartbeat:Connect(function()
print(Character.HumanoidRootPart.Position)
print(HRP.AssemblyLinearVelocity)
end)
UIS.InputBegan:Connect(function(Key)
print(LinearVelocity.VectorVelocity)
if FlyEnabled == true then
if Key == Enum.KeyCode.W then
LinearVelocity.VectorVelocity = Vector3.new(0,0,1)
end
end
end)
local function Fly()
end
Button.MouseButton1Click:Connect(function()
FlyEnabled = not FlyEnabled
if FlyEnabled then
LinearVelocity.Enabled = true
Button.BackgroundColor3 = Color3.fromRGB(54, 204, 12)
elseif not FlyEnabled then
LinearVelocity.Enabled = false
Button.BackgroundColor3 = Color3.fromRGB(204, 0, 0)
end
end)
Do someone identify the problem ? Is it possible to solve it ?
Thank you !