Camera tween not working

Hey!

I’m trying to tween player’s camera on part (clickDetector) MouseClick. However, it doesn’t work at all.

I tried using both LocalScript and ServerScript, but that didn’t help me, and I don’t even get an error, which is the most annoying part.

This is the code:

local clickDetector = script.Parent
local TweenService = game:GetService("TweenService")
local camera = game.Workspace.CurrentCamera

clickDetector.MouseClick:Connect(function()
	local TweenInfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false
	)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = game.Workspace.Computer.Monitor.monitor.TweenFirstPosition.CFrame

	local tween = TweenService:Create(camera, TweenInfo, {CFrame = game.Workspace.Computer.Monitor.monitor.CameraPosition.CFrame})
	tween:Play()
end)

1 Like

Is this a local script or a server script??

It’s currently a ServerScript.

It might have to do with the 0 part, because that’s how many times the tween is being repeated, so if the tween is being repeated 0 times, it wont play.

Not true, that’s the amount of times that it repeats after tweeting once.

1 Like

That didn’t help me either, even if it’s on ServerScript.

That’s because CurrentCamera is only for local scripts, while workspace.Camera is for server scripts.

1 Like

Could you try to print when the MouseClick fires to see if it even triggers?

I suggest using FireClient for the ServerScript.

I’m now getting an error “Argument 1 missing or nil”.

This is the ServerScript code:

local clickDetector = script.Parent
local event = game.ReplicatedStorage.ComputerCamera

clickDetector.MouseClick:Connect(function()
	event:FireClient()
end)

This is the LocalScript code:

local TweenService = game:GetService("TweenService")
local camera = game.Workspace.CurrentCamera
local event = game.ReplicatedStorage.ComputerCamera

event.OnClientEvent:Connect(function()
	local TweenInfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false
	)
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = game.Workspace.Computer.Monitor.monitor.TweenFirstPosition.CFrame

	local tween = TweenService:Create(camera, TweenInfo, {CFrame = game.Workspace.Computer.Monitor.monitor.CameraPosition.CFrame})
	tween:Play()
end)
1 Like

You need to put the player inside of FireClient()
like this FireClient(player) (MAKE SURE ITS NOT CHARACTER)

1 Like

Thanks, tweening is now working perfectly.

2 Likes

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