Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year ago

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

Log in to vote
0
Answered by 1 year ago
mouse.Move:Connect(function()
            Part.CFrame = CFrame.new(Part.CFrame.Position,mouse.Hit.Position)
       end)
Ad

Answer this question