So I'm making a plane script that replaces the character on spawn but I want the part to follow wherever I click/click and hold like in most plane games but mine it bugs out and sets the velocity very high and the rotation very awkwardly
The issue is on line 49 and line 50 I included the whole script just incase something else somewhere else ended up being the cause
--Plane Creator--
local Workspace = game:GetService("Workspace")
local Lighting = game:GetService("Lighting")
local StarterGui = game:GetService("StarterGui")
local StarterPack = game:GetService("StarterPack")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
print(player.Name)
local speed = 0
local Engine = false
local c = Instance.new("Model", workspace)
local a = Instance.new("Part", c)
local b = game.Workspace.Camera
local f = Instance.new("NumberValue", c)
local d = Instance.new("BodyVelocity", a)
local e = Instance.new("NumberValue", c)
a.Size = Vector3.new(2, 2, 4)
a.Position = Vector3.new(0, 2.5, 0)
a.Name = "Engine"
b.CameraSubject = a
b.CameraType = "Attach"
c.Name = player.Name .. "'s Plane"
d.Name = "Velocity"
d.Velocity = Vector3.new(0, 0, 0)
e.Name = "Speed"
e.Value = 15
speed = e.Value
f.Name = "Health"
f.Value = 100
-- inputs
function onKeyPress(inputObject, gameProcessedEvent)
-- variables
local input = game:GetService("UserInputService")
local W = inputObject.KeyCode == Enum.KeyCode.W
local A = inputObject.KeyCode == Enum.KeyCode.A
local D = inputObject.KeyCode == Enum.KeyCode.D
local F = inputObject.KeyCode == Enum.KeyCode.F
local E = inputObject.KeyCode == Enum.KeyCode.E
local x1 = d.Velocity.x
local y1 = d.Velocity.y
local z1 = d.Velocity.z
--d.Velocity = d.Velocity + mouse.hit.p
mouse.Button1Down:connect(function(down)
a.Rotation = mouse.hit.p -- ISSUE HERE
d.Velocity = mouse.hit.p -- ISSUE HERE
end)
if A then
a.Rotation = a.Rotation + Vector3.new(0,0 ,-15)
--d.Velocity = Vector3.new(-speed, y1, z1)
elseif D then
a.Rotation = a.Rotation + Vector3.new(0,0 ,15)
--d.Velocity = Vector3.new(speed, y1, z1)
elseif F then
local ray = Ray.new(a.CFrame.p, (mouse.Hit.p - a.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Bright red")
beam.FormFactor = "Custom"
beam.Material = "Neon"
beam.Transparency = 0
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (a.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(a.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(beam, 0.1)
elseif E then
if Engine == false then
Engine = true
print("Engine on")
local i = 1
while i < 10 do
i = i + 1
speed = speed + 2
end
else
Engine = false
print("Engine off")
end
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Right now I have the script in the StarterPlayerScripts inside the StarterPlayer
