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

Camera tweening won't work at all, no errors in output. Why?

Asked by 3 years ago
Edited 3 years ago

I am trying to make it so when this cannon script runs, 1 of the things that happens is your camera moves its location with tweening. Interpolate wouldn't work at all, and it is discouraged. Any idea how I can fix this script?

local Workspace = game:GetService("Workspace")
local UserInputService = game:GetService("UserInputService")
local PlayerName = script.Parent.Parent.Parent.Name
local Character = Workspace[PlayerName]
local Cannon = Workspace.Cannon

UserInputService.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        for i, v in pairs(Character:GetDescendants()) do
            v.Anchored = true 
        end
-- Code below here is setting up the camera
        local cam = workspace.CurrentCamera
        local TweenService = game:GetService("TweenService")
        local tweenInfo = TweenInfo.new(
            2,
            Enum.EasingStyle.Quint,
            Enum.EasingDirection.Out,
            0,
            false
        )
        local tweenProperties = {
            CFrame = CFrame.new(Cannon.EndPart.Position, Cannon.EndPart.Orientation)
        }
        local Tween = TweenService:Create(cam, tweenInfo, tweenProperties)
        cam.CameraType = "Scriptable"
        Tween:Play()
    end
end)

There are no issues with the code running in the first place, it just won't work.

1 answer

Log in to vote
1
Answered by
SteamG00B 1633 Moderation Voter
3 years ago
Edited 3 years ago

The order of arguments in a function does matter. What you did was create the tween with the arguments in backwards order, and as I've never done that before, I am not sure why it didn't give you an error, but this is how you fix it on line 25:

local Tween = TweenService:Create(cam, tweenInfo, tweenProperties)

EDIT:

Alright, there is one thing that you should change because it's simply a bad practice, and one reason why I believe it is not working how you want it to.

First one, don't name UserInputService USI. If your goal was to use an acronym, your letters should be in order, so you should get into the habit of making your code easy to follow just in case you decide to join or make your own dev team later on.

Second one, your CFrame goal is starting at a position and looking towards another position that is made up of your parts orientation. That won't work, but unless that's what you wanted it to do, then I don't know why else it wouldn't work.

0
@cookie_more Notice the order of parameters in the tool-tip as you type and at https://developer.roblox.com/en-us/api-reference/function/TweenService/Create AlexTheCreator 461 — 3y
0
It didn't change anything. Your definitely right, but it still isn't working. cookie_more 30 — 3y
0
Made an edit. SteamG00B 1633 — 3y
0
Just making a comment to remind you that your question is still unanswered. Does it work or not? SteamG00B 1633 — 3y
Ad

Answer this question