Why doesn't this set the camera to the player?

I’m trying to make it so that if the player clicks a button, it sets the camera type to the player camera, so that the tween stops running, and the camera type is no longer scriptable.

Here’s my code:

script.Parent.MouseButton1Click:Connect(function()
	local camera = game.Workspace.Camera
	camera.CameraType = Enum.CameraType.Custom
	script.Parent.Parent.Parent.Enabled = false
end)

Another script is animating the camera too, could that be causing the issue?

Summary
local TweenService = game:GetService("TweenService")
local cams = game.Workspace.Cameras
local done = false

local camera = game.Workspace.Camera

local sceneTime = 20

local tweeninfo = TweenInfo.new(
	sceneTime,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	true,
	0
)

function tween(camera1, camera2, ending)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = camera1.CFrame

	local tween = TweenService:Create(camera, tweeninfo, {CFrame = camera2.CFrame})
	tween:Play()

	wait(sceneTime)

	if ending then
		camera.CameraType = Enum.CameraType.Custom
	end

end


tween(cams.Camera1, cams.Camera2, false)
--wait(20)
tween(cams.Camera3, cams.Camera4, false)
--wait(20)
tween(cams.Camera5, cams.Camera6, false)
--wait(20)
tween(cams.Camera7, cams.Camera8, false)
--wait(20)
tween(cams.Camera9, cams.Camera10, true)

Why would this not work?

Would I also have to stop the other script (with the camera tweens) If so, then how would I accomplish that?

Thanks!

EDIT: My new issue is that the camera tweens to the player, instead of teleporting to another camera.

You should use

local camera=workspace.CurrentCamera
1 Like

The same problem still occurs.

I’m starting to think it’s the other script’s issue, as the UI does disappear, but they camera doesn’t get set.

Is there a way to make it (the other camera animation) reset/stop? The button script is a LocalScript in StarterGui and the camera tween is a LocalScript inside StarterPlayerScripts.

It doesen’t change anything because it’s the same thing.

Try to change Enum.CameraType.Custom with Enum.CameraType.Fixed.

What is CameraType.Fixed? I’ve never heard of it.

When you set the camera to Fixed, it makes the player’s camera stationary.

1 Like

Wouldn’t that make it so the player is unable to move their camera? I want it so that it sets the camera to the player, and continues to be like that.

Setting the camera type to fixed unfortunately provides the same results as custom.

Is there a way to disable the tween in the other script?

I have no idea how to pause the tween as soon as the button is pressed, but would constant “if” statements work?

I don’t know how to use module scripts but this discussion may help you.

https://devforum.roblox.com/t/running-functions-in-a-different-script-than-the-one-i-created-it-in/

Not exactly what I’m looking for… I’m trying to make the player’s camera change on click. Thanks anyways!

I also tried adding the function to the camera tween script, but it didn’t work.

Maybe add these lines of code under the camera.CameraType = Enum.CameraType.Custom?

local player = game.Players.LocalPlayer
local character = workspace:FindFirstChild(player.Name)
if character then
	camera.CameraSubject = character
end

You can modify this code to however you like. I hope this helps!

1 Like

Unfortunately that also provides the same results.

Just a quick question, is your character in the workspace during this time period?

Correct. The humanoid’s walkspeed is 0 though.

If you’re currently in Studio, can you test play and try going to the properties in Workspace => Camera => CameraSubject, and change the CameraSubject to your character after your tween is finished and see if it works?

1 Like

I checked the CameraSubject, and it is the humanoid, even when the tween is running, and after the tween, it’s the same.