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

How do i make a Part look at the spot where the mouse clicked?

I'm trying to make a spaceship (but i'm testing with just a seat), when you sit in the spaceship, you can click in whatever place in the screen & the spaceship will look at the spot you clicked, i need help.

(btw if you played Moon Tycoon, and you have a spaceship, you know what i'm talking about.)

Here's the script i used in my place

local player
local mouse

local function onClicked()
	script.Parent.CFrame = CFrame.new(script.Parent.Position, mouse.Hit.Position) --Script.Parent is the seat
end

script.Parent.Touched:connect(function(hit)
	if hit and hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
		player = game.Players:FindFirstChild(hit.Parent.Name)
		
		mouse = player:GetMouse()
		
		mouse.Button1Up:connect(onClicked)
	end
end)

but it doesn't work!

if you have a better idea, or if you know what to do here, tell me plz! :c Please! If someone knows how to make the Moon Tycoon's Spaceship, TELL ME! ...or if you know how to edit the Personal Rocketship without all the Tool stuff, and making it just for a seat

1 answer

✓ Accepted answer

You can make a part face a direction with CFrame's second parameter.

Example (localscript, and not FilteringEnabled):

local part = Instance.new("Part", workspace) -- Create a new Part instance and parent it to workspace.
local mouse = game.Players.LocalPlayer:GetMouse() -- Get localplayer's mouse

part.CFrame = CFrame.new(part.Position, mouse.Hit.p) - You will set the CFrame of the part to where it is, but it will face towards the mouse's position

To add this to your spaceship would be pretty simple.

Here is an example, I'm assuming your spaceship has a primarypart. I am also assuming your spaceship is a model.

local mouse = --tag the mouse, for this example i'll just leave it blank
SpaceShip:SetPrimaryPartCFrame(CFrame.new(SpaceShip:GetPrimaryPartCFrame(), mouse.Hit.p))

4 comments

0

you don't put the script anywhere... I'm not giving you the script for the whole thing, I'm just giving a way you could do this.

0

oh ok

0

is there a way i can do this with a server script?

0

btw i think i'm gonna be using BodyGyro and BodyForce :/

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