Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a part point where the players mouse is facing when they are are sat in a seat?

Hello, I am currently working on a script for a tank where when the player is sat in the tank seat they can aim the turret on the front. I tried using a remote event to get the mouse position but then remembered that you cannot pass mouse properties. So, I placed a Local Script in StarterGui. It detects when the player sits but i cannot get the turret to then face where the mouse is pointing. Any help would be great!

Script in StarterGui:

local mouse = game.Players.LocalPlayer:GetMouse()
local Part = game.Workspace.tank.shoot
game.Workspace.tank.Vehicle1.VehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if game.Workspace.tank.Vehicle1.VehicleSeat.Occupant ~= nil then
		print("player sat")
		Part.CFrame = CFrame.new(Part.CFrame.p,mouse.Hit.p)
	end
end)

1 answer

mouse.Move:Connect(function()
			Part.CFrame = CFrame.new(Part.CFrame.Position,mouse.Hit.Position)
	   end)

This discussion is preserved as it was. New answers, comments, and votes are closed.