Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i use the tweening service with camera manipulation?

Im trying to tween my camera to a part but i keep getting this error -

 ** 00:21:45.615 Unable to cast to Dictionary - Client - cam:25**

This is my Code

cam = workspace.CurrentCamera
local Tween = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local char = player.Character
local touchPart = game.Workspace.touchPart
local camPart = game.Workspace.FocusPart
camPart2 = game.Workspace.FocusPart2
 camType = Enum.CameraType.Scriptable

touchPart.Touched:Connect(function(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	if human then 
	local info = 	TweenInfo.new(
			2,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.In,
			0,
			true,
			1
		)
		local Goals = {
			Focus = game.Workspace.FocusPart.CFrame
			}
		
		local start = Tween:Create(info, Goals, camType)
		start:Play()
	end
	
end)

Please help!!!

1 answer

✓ Accepted answer

Your Goals is the problem. What even is Focus? The name should be a valid property of the thing you are trying to tween. The way you Tween:Create() at Line 25 is very wrong too. First parameter should be the object you are tweening. Which in this case, is the camera. Second parameter is your TweenInfo and third is your goals. You definitely have to know API reading.

TweenService: https://developer.roblox.com/en-us/api-reference/class/TweenService

cam = workspace.CurrentCamera
local Tween = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local char = player.Character
local touchPart = game.Workspace.touchPart
local camPart = game.Workspace.FocusPart
camPart2 = game.Workspace.FocusPart2
camType = Enum.CameraType.Scriptable

touchPart.Touched:Connect(function(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	if human then 
		local info = TweenInfo.new(
			2,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.In,
			0,
			true,
			1
		)
		local Goals = {
			CFrame = game.Workspace.FocusPart.CFrame --means we're going to change the CFrame of your object which is cam
		}

		local start = Tween:Create(cam, info, Goals) --(Object, TweenInfo, goals)
		start:Play()
	end

end)

1 comment

0

Thank you very much for the answer

This discussion is preserved as it was. New answers, comments, and votes are closed.