Hello!
I have been trying for the past couple of days to make a working spaceship using bodygyro and bodyvelocity.
Goal: To make a working spaceship using bodyvelocity and bodygyro.
Problem: It doesn't fly and it gives me an error message. (Workspace.WH_HAN.LocalScript:8: attempt to index nil with 'Position')
Current scripts: (local script Inside the player character)
local ship = workspace.Spaceship
local player = game.Players.LocalPlayer
local gyro = ship.BodyGyro -- these body movers are to be placed in the main part inside the model
local bodyvelocity = ship.BodyVelocity
local ship_model = workspace.Spaceship
local function flyShip()
gyro.CFrame = CFrame.new(ship_model.PrimaryPart.Position, player:GetMouse().Hit.p)
local Direction = ship:GetPrimaryPartCFrame().lookVector
bodyvelocity.Velocity = Direction * 65 -- can be any value for speed
end
game:GetService("RunService").RenderStepped:Connect(flyShip)
I also did set the player's network ownership (I think at least) (Script is inside the seat for the spaceship)
local VehicleSeat = script.Parent
VehicleSeat.Changed:Connect(function(prop)
if prop == "Occupant" then
local humanoid = VehicleSeat.Occupant
if humanoid then
local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
if player then
VehicleSeat:SetNetworkOwner(player)
end
else
VehicleSeat:SetNetworkOwnershipAuto()
end
end
end)
I'm sorta new to scripting and I wouldn't be surprised if I had to redo my entire code. If anyone can help me out, Thanks in advance!
