Main menu Camera + Manipulation, using click detectors

Hi Guys, I’m struggling to make camera manipulation system with tweening and a click detector work the way it should, which is, if the player clicks the click detector within the part in game, it would Tween the current camera(its a part camera not a player camera) to wherever the script wants to Cframe the camera to, which in my case, I want it to tween to another part camera. How can I Do this, I have this script and it is in starterplayerscripts, and its a local script but it seems like it doesn’t work.

Script:

> local cam = workspace.CurrentCamera
> local TS = game:GetService("TweenService")
> 
> local function Tween(pos, tweenTime) Click.MouseClick:Connect(Tween(workspace.AboutCamera, 4))
> 	TS:Create(cam, TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {CFrame = pos.CFrame}):Play()
> end
> 
> Tween(workspace.AboutCamera, 4)
1 Like

Can you show me a larger part of your script?

That’s all I got man sorry, Can you still help?

set the cameratype to Enum.scriptable

Can you explain what this part on the script?

Ok, so I can see a lot of discrepancies in your code -

When connecting a function using the MouseClick event, it sets the parameter to the player who clicked it, thus any variables you send over are null and void.

To fix this, you need to swap around the way your functions work:


local function Tween(pos, tweenTime)
	TS:Create(cam, TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {CFrame = pos.CFrame}):Play()
end


Click.MouseClick:Connect(function(Player) -- where Click is the MouseDetector in your part, you have to define this as a variable.
	Tween(workspace.AboutCamera, 4)
end)

EDIT:

Also do this

2 Likes

Ok thanks ill give it a go, and let you know what happens

Its not working Is it supost to be in the click detector or something?

Re-post your edited code please, I’ll let you know from there

Firstly, you’re defining the Tween function, and inside it, you have a connection to the MouseClick event, which is incorrect. You should connect the MouseClick event to the Tween function outside the definition. Secondly, the Click object is not defined in your script. You need to add a reference to the ClickDetector in your game.

Here’s an updated version of your script:

local cam = workspace.CurrentCamera
local TS = game:GetService("TweenService")

-- Add a reference to the ClickDetector in your game
local clickDetector = workspace.ClickDetectorPart.ClickDetector -- Replace ClickDetectorPart with the name of the part that has the ClickDetector

local function Tween(pos, tweenTime)
	TS:Create(cam, TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {CFrame = pos.CFrame}):Play()
end

-- Connect the MouseClick event to the Tween function
clickDetector.MouseClick:Connect(function()
	Tween(workspace.AboutCamera, 4)
end)

-- Optionally, you can remove the following line if you don't want to tween the camera when the script starts
Tween(workspace.AboutCamera, 4)

Make sure to replace ClickDetectorPart with the name of the part that has the ClickDetector in your game. This script should now work as intended. When the player clicks the part with the ClickDetector, the camera will tween to the specified part camera.

Okay, I’ve edited it, and it hasn’t worked, do I need to move the click part out of the model and into the workspace by itself? because its inside a a folder which holds all the sections “About, Credits, Play and main” it sits in a model inside of main…if you can understand what I’ve stated…Here is the code with the edits you wanted me to do:

local cam = workspace.CurrentCamera
local TS = game:GetService("TweenService")

-- Add a reference to the ClickDetector in your game
local clickDetector = workspace.Menu.Main.About.AboutButton.ClickDetector -- Replace ClickDetectorPart with the name of the part that has the ClickDetector

local function Tween(pos, tweenTime)
	TS:Create(cam, TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {CFrame = pos.CFrame}):Play()
end

-- Connect the MouseClick event to the Tween function
clickDetector.MouseClick:Connect(function()
	Tween(workspace.AboutCamera, 4)
end)

-- Optionally, you can remove the following line if you don't want to tween the camera when the script starts
Tween(workspace.AboutCamera, 4)

Plus Is it in a local script and what is it supposed to be parented under?

I currently have it in StarterPlayerScripts inside of a local script.

@76IOOO Ok i got it working, after i edited it i realised that it doesnt register the click, i was sitting there spamming and it would only work sometimes. instead of working with one click, also it doesnt stay at the camera, How should i fix these problems