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

The issue it does not solve however, is the issue where the camera tweens (e.g. from cams 1-2) to the right spot, and then to the player, instead of going to cams 3-4.

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

you need to do,


local SetCameraMode = game.ReplicatedStorage.SetCameraMode

local TextButton = game.StarterGui.ScreenGui.TextButton

game.Players.PlayerAdded:Connect(function(Player)
	TextButton.MouseButton1Click:Connect(function()
		local Camera = game.Workspace.Camera
		
		SetCameraMode:FireClient(Player, Camera)
	end)
end)
game.ReplicatedStorage.SetCameraMode.OnClientEvent:Connect(function(Camera)
	Camera.CameraType = Enum.CameraType.Custom
	
	local WaitTime = 20
	
	local Tween = TweenInfo.new(
		WaitTime,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		true,
		0
	)
	
	Tween:Play()
end)
end)

This allows it for the client to have its CameraType to custom.

Really? I didn’t do that for my newest script and it worked just fine.

@BlueMinionIW @DargoA @TrashMakeRice
I actually want the camera tween to be looped, what changes would I need to make to fix that?

Latest Code:

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

local camera = game.Workspace.Camera

local sceneTime = 20

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

local player = game.Players.LocalPlayer

function TweenFunction(camera1, camera2, ending)
	if forcestop == false then
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = camera1.CFrame

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

		tween.Completed:Wait()

		if ending and forcestop == false then
			camera.CameraType = Enum.CameraType.Custom
			local character = player.Character
			if character then
				camera.CameraType = Enum.CameraType.Custom --temp
				camera.CameraSubject = character
			end
		end
	end

end

script.Parent.MouseButton1Click:Connect(function()
	if tween then
		tween:Cancel()
		tween:Cancel()
		tween:Cancel()
		tween:Cancel()
		tween:Cancel()
	end
	camera.CameraType = Enum.CameraType.Custom
	local character = workspace:FindFirstChild(player.Name)
	if character then
		camera.CameraSubject = character
	end
	script.Parent.Parent.Parent.Enabled = false
	forcestop = true
end)

if not forcestop then
	TweenFunction(cams.Camera1, cams.Camera2, false)
end

--wait(20)

if not forcestop then
	TweenFunction(cams.Camera3, cams.Camera4, false)
end

--wait(20)

if not forcestop then
	TweenFunction(cams.Camera5, cams.Camera6, false)
end

--wait(20)

if not forcestop then
	TweenFunction(cams.Camera7, cams.Camera8, false)
end

--wait(20)

if not forcestop then
	TweenFunction(cams.Camera9, cams.Camera10, true)
end
1 Like

Try it maybe. You want a transition? if so, I can probably do that.

Hello, i’m back!
So you want it to loop until the person cancels it?

1 Like

Yes, I want it to loop until cancel. Could you tell me if my half-solution (spamming cancel tween) is a good way?

Well, if you want to make 100% sure the tween was cancelled, i think 3 times is enough
If somehow you get a perfectly timed tween that you cancel but it activates it, the second or the third would stop the tween from happening.

Also, you can do this if you want to make it repeat:

repeat
 if not forcestop then
    TweenFunction(cams.Camera1, cams.Camera2, false)
 end

 --wait(20)

 if not forcestop then
 	TweenFunction(cams.Camera3, cams.Camera4, false)
 end

 --wait(20)

 if not forcestop then
 	TweenFunction(cams.Camera5, cams.Camera6, false)
 end

 --wait(20)

 if not forcestop then
	TweenFunction(cams.Camera7, cams.Camera8, false)
 end

--wait(20)

 if not forcestop then
	TweenFunction(cams.Camera9, cams.Camera10, true)
 end

until forcestop
1 Like

I did mine the number of times the camera is tweened, not sure if that has any connection.

I’m also still having that issue where the camera tweens from camera1 to 2, then goes to the player, then camera3.

What do you mean?
I didn’t exactly understand that phrase, sorry.

I’ll just keep mine at that amount for now, I wanted to know if it was a good solution or not.

My main problem at the moment is where the camera tweens to the player.

I edited mine. If you want to check it out if you want.

1 Like

So for example

This works fine, but when it’s gonna switch to the next function the camera goes to the player and then after the wait is done it goes to the next tween?

1 Like

Correct… mostly.

It finishes the tween from camera 1, to camera 2.
Then, it tweens to the player.
Then, it teleports to camera 3, and acts like nothing ever happened.

Then it repeats. Every time a tween is completed, it goes to the player.

I think the reason that happens is because when the tween ends, the own ROBLOX default configuration brings the camera back to the character. I can be wrong, but this is my theory.

Remove all the waits and try the script again.

All my waits are commented out though.
The effect I’m trying to achieve can be seen in the roblox game World of Magic, on the play screen.

1 Like

Ah yes, i think i know what you mean now.
Let me see what i can do.

Can you send your most recent code? @RipPBB_TUD

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

local camera = game.Workspace.Camera

local sceneTime = 20

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

local player = game.Players.LocalPlayer

function TweenFunction(camera1, camera2, ending)
	if forcestop == false then
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = camera1.CFrame

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

		tween.Completed:Wait()

		if ending and forcestop == false then
			camera.CameraType = Enum.CameraType.Custom
			local character = player.Character
			if character then
				camera.CameraType = Enum.CameraType.Custom --temp
				camera.CameraSubject = character
			end
		end
	end

end

script.Parent.MouseButton1Click:Connect(function()
	if tween then
		tween:Cancel()
		tween:Cancel()
		tween:Cancel()
		tween:Cancel()
		tween:Cancel()
	end
	camera.CameraType = Enum.CameraType.Custom
	local character = workspace:FindFirstChild(player.Name)
	if character then
		camera.CameraSubject = character
	end
	script.Parent.Parent.Parent.Enabled = false
	forcestop = true
end)

repeat
	if not forcestop then
		TweenFunction(cams.Camera1, cams.Camera2, false)
	end

	if not forcestop then
		TweenFunction(cams.Camera3, cams.Camera4, false)
	end

	if not forcestop then
		TweenFunction(cams.Camera5, cams.Camera6, false)
	end

	if not forcestop then
		TweenFunction(cams.Camera7, cams.Camera8, false)
	end

	if not forcestop then
		TweenFunction(cams.Camera9, cams.Camera10, true)
	end

until forcestop
1 Like