Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i use the tweening service with camera manipulation?

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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)
0
Thank you very much for the answer bestshot123 38 — 2y
Ad

Answer this question