Forcing players view to part when GUI is clicked (and reverse)

I’ve been trying to make a script that does the following:
When player touches a GUI, I want their camera/view to face towards what is infront of the part (aka the stage) and when they click the GUI again their camera/view reverts back to their normal player view
Here is an example;


Can anyone help me make this? Thanks to anyone who can help by providing it.

3 Likes

Forgot to add - credits to honey&tea for the example video.

2 Likes

I’m confused… in the video, you’re the one doing the example. It looks like you already made it? But anyway, when you click the GUI, you should make a script to tween the player’s camera to where you want (after setting CameraType to Scriptable), and when you click it again, tween the camera back to the player, and make the CameraType set to Custom.

2 Likes

It’s from another game. Not my game.

1 Like

Heres the script I made up:

--> this is a local script, in a ScreenGUI
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local button = script.Parent.Button
local looking = false
local endCFrame = CFrame.new() --> put the CFrame of where you want the camera to end up here
local tweentime = 3
local debouncetime = 0.5
local active = false
button.MouseButton1Click:Connect(function()
    if active then return end active = true
    looking = not looking
    if looking then
    	camera.CameraType = Enum.CameraType.Scriptable
    	game.TweenService:Create(camera, TweenInfo.new(tweentime, Enum.EasingStyle.Sine, Enum.EasingDirection.Out,0,false,0), {CFrame = endCFrame}):Play()
	    wait(tweentime+debouncetime)
	else
     	camera.CameraType = Enum.CameraType.Custom
	    wait(debouncetime)
    end
    active = false
end)
4 Likes

Thank you so much,. will test it later and mark as solved if it works.

2 Likes

I tested it in one of my games, and it seems to be working. You just need to add where you want the camera to end up, and make sure you have a button called Button in a ScreenGui. https://gyazo.com/ae9f70b5cbc26103db665ccdf66112ca

2 Likes

Awesome! Does the button need a clickdetector?

1 Like

No, GUI buttons do not need click detectors.

2 Likes

CFrame… how do I find this?
Sorry for asking lots of questions, I’m new to scripting and am trying to learn and this helps as I always review the scripts.

1 Like

I can’t really explain what CFrame is, but it basically determines a BasePart’s Position and Orientation. CFrame includes alot of handy functions for different situations. To get a BasePart’s CFrame, you can say Part.CFrame (a hidden property).

2 Likes

That’s all I needed, thank you!

3 Likes

I have also been recently struggling to complete this. Thank you so much; I appreciate it.

1 Like