I want to make my flying broomstick rotate to the camera orientation. I had it working before in like 2020 but it randomly stopped working (I even went back to an auto-save of when it was working, and it turns out it is broken there now!?).
The issue is that when I look in one direction (turn the camera using the mouse), the broomstick keeps rotating, rather than coming to a stop at where the player is facing on the broomstick. I have googled all over, looked all over the Dev Hub, asked in discords, etc. I have been looking for many months to find a solution, but I can’t find one! If you need any more detail, just let me know and I’ll happily describe it further.
This is the code I am currently using (that is not working):
local player = game:GetService('Players').LocalPlayer
local seat = game.Workspace:WaitForChild(player.Name.."'s CheapSweep4").Seat
local BodyGyro = game.Workspace:WaitForChild(player.Name.."'s CheapSweep4").Seat.BodyGyro
local stick = game.Workspace:WaitForChild(player.Name.."'s CheapSweep4").Stick
local run = game:GetService("RunService")
local cam = workspace.CurrentCamera
seat.Changed:Connect(function(property)
if property ~= "Occupant" then return end
local occupant = seat.Occupant
if seat.Occupant then
local connection
connection = run.Stepped:Connect(function()
if seat.Occupant == false then
connection:Disconnect()
return end
local midpt = cam.ViewportSize/2
local direction = cam:ViewportPointToRay(midpt.X, midpt.Y).Direction
BodyGyro.CFrame = CFrame.new(Vector3.new(), direction)
end)
end
end)
local player = game:GetService('Players').LocalPlayer
local seat = game.Workspace:WaitForChild(player.Name.."'s CheapSweep4").Seat
local BodyGyro = game.Workspace:WaitForChild(player.Name.."'s CheapSweep4").Seat.BodyGyro
local stick = game.Workspace:WaitForChild(player.Name.."'s CheapSweep4").Stick
local run = game:GetService("RunService")
local cam = workspace.CurrentCamera
seat.Changed:Connect(function(property)
if property ~= "Occupant" then return end
local occupant = seat.Occupant
if seat.Occupant then
local connection
connection = run.Stepped:Connect(function()
if seat.Occupant == false then
connection:Disconnect()
return end
local midpt = cam.ViewportSize/2
local direction = cam.CFrame.Orientation
BodyGyro.CFrame = CFrame.new(Vector3.new(), direction)
end)
end
end)
local run = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local camera = workspace.CurrentCamera
local vehicle = workspace:WaitForChild(player.Name.."'s CheapSweep4")
local seat = vehicle:WaitForChild("Seat")
local bodyGyro = seat:WaitForChild("BodyGyro")
local stick = vehicle:WaitForChild("Stick")
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local occupant = seat.Occupant
if not occupant then return end
local connection
connection = run.Stepped:Connect(function()
if seat.Occupant ~= occupant then
connection:Disconnect()
end
local middle = camera.ViewportSize/2
local ray = camera:ViewportPointToRay(middle.X, middle.Y)
bodyGyro.CFrame = CFrame.lookAt(ray.Origin, ray.Direction * 250)
end)
end)