Camera isn't going back to player once I press this button

So, I have this script where, when you press the button it shifts the camera to an object, and then of course there is another button to shift it back to its original object. Problem is, after I’ve pressed these buttons, the play button doesn’t return the camera back to the player.

I’ve tried every solution I could think of, but also, the script is pretty old and bad.
I’m wondering if there’s a better way to do this and, a way to fix this problem?

Here’s the script:

local camera = game.Workspace.Camera

local play = script.Parent.Parent.Play

local player = game.Players.LocalPlayer

local amount = 999999

local function cameraTween()
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = game.Workspace.Cameras.Cam3.CFrame

	local info = TweenInfo.new(amount,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

	local tween = TweenService:Create(camera,info,{CFrame = game.Workspace.Cameras.Cam3.CFrame})
	tween:Play()
end

script.Parent.MouseButton1Click:Connect(function()
	workspace.SFX["button.wav"]:Play() -- sound effects
	cameraTween()
	play.Active = true
	script.Parent.Visible = false
end)

That’s the camera that shifts it back to its original object

Here’s the play button script:

local camera = game.Workspace.Camera

script.Parent.MouseButton1Click:Connect(function()

	camera.CameraType = Enum.CameraType.Custom
	camera.CFrame = player.Character.Head.CFrame

end

If you need any more information, let me know.

I’ve tried doing this with events, but I realized that I can’t because everything is on a local script.

You can do this with events, actually. When you fire a BindableEvent, it can still be recognized by the script that fired it.

1 Like

Ooh, I didn’t know that. I’ll definitely look things up about it.
But do you think it would solve this issue? If so, how?

I would use a bindableEvent like this:

local camera = game.Workspace.Camera

local play = script.Parent.Parent.Play

local player = game.Players.LocalPlayer

local amount = 999999

local bindableEvent = --where your bindableEvent is

local function cameraTween()
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = game.Workspace.Cameras.Cam3.CFrame

	local info = TweenInfo.new(amount,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

	local tween = TweenService:Create(camera,info,{CFrame = game.Workspace.Cameras.Cam3.CFrame})
	tween:Play()
end

script.Parent.MouseButton1Click:Connect(function()
	workspace.SFX["button.wav"]:Play() -- sound effects
	cameraTween()
	play.Active = true
	script.Parent.Visible = false
        bindableEvent:Fire()
end)

and for the play button script:

local camera = game.Workspace.Camera
local bindableEvent = --where your bindableEvent is
bindableEvent.Event:Connect(function()

	camera.CameraType = Enum.CameraType.Custom
	camera.CFrame = player.Character.Head.CFrame

end

I would also put the BindableEvent somewhere in the starterPlayer or starterPlayerScripts.

1 Like

It unfortunately didn’t work :sad:

what happened? Was there an error?

there was no error, the camera didnt shift back into place after pressing the button and did not go to the players head when i clicked play

local amount = 999999
local info = TweenInfo.new(amount,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

Why are you creating a 999999 second long tween?

because i want it to last forever UNTIL you press the button

edit: i have done repeat wait until mousebutton1click (referring to the play button)
but im not sure that i have done it correctly…

When the play button is pressed the tween is still playing, so once you change the CFrame it will be changed back straight away. Try stopping the tween using tween:Pause() when the play button is pressed.

1 Like

when a player joins the server just set their camerasubject to the part, and once they press play set their camerasubject to their humanoid.

1 Like

An Alternative to this also, is when the player joins set their Humanoids

Humanoid.CameraOffset

to the part, and once they press play set it back to 0 or the original offset.

1 Like

it kind of works! its just that it gives the error;

I’m guessing you are calling pause on the cameraTween function instead of the actual tween instance.

local tween = TweenService:Create(camera,info,{CFrame = game.Workspace.Cameras.Cam3.CFrame})
tween:Pause()

or

tween:Cancel()
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.