Help with tweening script for piggy game

Hey devforum members! So I was working on my piggy game where I encountered an error, the script was something to do with cam manipulation and when you press the textbutton the camera would go from one part to the next. Here is the script and if you can point out any errors that would be great! local camera = workspace.CurrentCamera

local mainMenuMap = workspace:WaitForChild("MainMenuMap")
local tweenService = game:GetService("TweenService")
local btn = script.Parent

function tweenCamera(pos,tweenTime)
     tweenService:Create(camera,TweenInfo.new(tweenTime,Enum.EasingStyle.Linear),{CFrame = pos.CFrame}):Play()
end

btn.MouseButton1Click:Connect(function()
    btn.Visible = false
    btn.Parent.Title.Visible = false

    tweenCamera(mainMenuMap.CameraPart2,1)
    wait(1)
    print("Reached Destination")
end)

What is the error you’re getting? Or is it just not behaving as it should?

It is not behaving as it should, I have opened other baseplates and tried the same script in a play button in startergui, still nothing.

It would be helpful if you could tell us what it is doing. I don’t see anything wrong with the script (yet).

Like when I hit the textbutton its supposed to move to the next camera manipulation part, but it does not I will try once again.

I just tried it once again it did not work. I did think it was because I copied the pseudocode from my phone because I scripted it last night and just transfered it over. Turns out that is not why.

Have you tried changing pos.CFrame to be CFrame.new(pos)?

Nevermind I noticed the function input in the part instance and not a Vector3 value

1 Like

You’re not getting any errors in the output window? If the tween isn’t playing, it would be good to check if your script is erroring before you call the tween.

Also, I’ve had a history with tweening failing (with GUIs) but I haven’t had any issues with TweenService before. I’ll look into this.

I suppose that would work but based on his script, the “pos” variable isn’t a position, it’s the brick in question - CameraPart2

That did not work any other suggestions?

I ran it and checked the output no errors, perhaps I can show you a video of what happens?

1 Like

Have you set your CameraType to Scriptable?

CameraType documentation

3 Likes

CameraType is scriptable, still nothing

Have you tried putting local in front of your function?

local function doStuff()
    --Function stuff here
end

Can you provide your script that mentions where you set the camera type, from your example it’s not shown. I can’t think of something else that could be restricting it from working properly.

What do you mean? I set the cameratype to scriptable in the camera setting on explorer.

You have to set it at the start of the local script.

local currentCamera = game.Workspace.CurrentCamera

currentCamera.CameraType = Enum.CameraType.Scriptable
1 Like

Nope. Still the same as it was before.

As @xZylter has mentioned, you need to set it by a local script, it’s up to you when you choose to set it for your use case. By default, the camera will be set to custom so it can follow and attach to your character.

Have you made the function a local function?