Why wont this work? ive done this millions of times

im trying to make a part follow the mouse when the player sits on the vehicle seat, however it just wont detect anything , the script is cloned and enabled inside the vehicle seat.

local WASD = {
	0,
	0,
	0,
	0
}

local function updatePosition()

end

local this = script.Parent.Parent

while wait() do

	local PlaneSeat = this:FindFirstChildOfClass("VehicleSeat")
	if PlaneSeat.Occupant ~= nil and game:GetService("Players"):GetPlayerFromCharacter(PlaneSeat.Occupant.Parent) then
		local mouse = game:GetService("Players"):GetPlayerFromCharacter(PlaneSeat.Occupant.Parent):GetMouse()
		if mouse then
			this.Body.CFrame = CFrame.lookAt(this.Body.Position,mouse.Hit.Position)
		end

	end
end

please help im dying

1 Like

is this a local script or a server script?

server script - 30 . . . . . . . . .

you cant get the player mouse from a server script

1 Like

Hello!

Try this in a LocalScript.

local WASD = {
	0,
	0,
	0,
	0
}

local function UpdatePosition()
	
end

local this = script.Parent.Parent

while task.wait() do
	local PlaneSeat = this:FindFirstChildOfClass("VehicleSeat")
	
	if PlaneSeat.Occupant ~= nil and game:GetService("Players"):GetPlayerFromCharacter(PlaneSeat.Occupant.Parent) then
		local mouse = game.Players.LocalPlayer:GetMouse()
		
		if mouse then
			this.Body.CFrame = CFrame.lookAt(this.Body.Position, mouse.Hit.Position)
		end
	end
end

Hope this helps!