I have this script that i would want so if i click on a script it opens a gui that you can click on and the camera goes to that object the mouse is over when you click the gui but i want it so the camera goes to the object you clicked on not the object the camera is over when you click the gui,

heres the script

Mouse.Button1Down:connect(function()
	if Mouse.Target then
		if Mouse.Target.Parent:IsA("Model") and Mouse.Target.Name == "Hitbox" then
			local TargetPos = workspace.CurrentCamera:WorldToScreenPoint(Mouse.Target.Position)		
			UI.Frame.Visible = true
			UI.Frame.Position = UDim2.new(0,TargetPos.X,0,TargetPos.Y)
			targeting = Mouse.Target.Parent
			
			UI.Frame.Sample.MouseButton1Click:connect(function()
				workspace.CurrentCamera.CameraSubject = Mouse.Target
				UI.Frame.Visible = false
			end)
			--script.Parent.Frame.ItemName.Text = Mouse.Target.Parent.Name
		else
			UI.Frame.Visible = false
		end
	else
		UI.Frame.Visible = false
	end
end)

3 comments

1

You would need to store the part when you click to be used at a later stage when you click the gui.

0

Ya i could do that but, i would want it so i just can click on every part with a part named hitbox in it, With one script like i have already but so if i click a object and then the gui the camera goes to that part not the part the mouse if hovering over

0

You said "but," then just restated your irrelevant premise. Store mouse.Target in a variable.