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

How can I halt this camera tween function after the player exits the menu?

Asked by
Azuc 112
6 years ago

Basically we are working on updating the camera in our game for our menu from being a static position to flying between positions, the issue we are currently having is once the player leaves the menu the camera will go back to the player like it should be it instantly starts flying to the spots outlined in the tween function until the wait statements have finished.

Not really sure how to break the function once the player spawns, some input would be greatly appreciated:

local Camera = game.Workspace.CurrentCamera
local Tween = game:GetService("TweenService")

function zoomToCam(part, seconds)
    Tween:Create(Camera, TweenInfo.new(seconds), {CoordinateFrame = part.CFrame}):Play()
end

local TweenMenu = function(Value)
    local Camera = game.Workspace.CurrentCamera
    local CameraStart = game.Workspace:WaitForChild("CameraPart")
    local Angle = 0


    Menu.Visible = Value
    Background.Visible = Value
    BackgroundImage.Visible = Value
    Updates.Visible = false
    Teams.Visible = false
    Load.Visible = false


    Opened = Value

    -- Menu is open, alter player's camera
    if Value == true then
        -- camera is a movin, move outta ma way
        repeat
            wait()
            Camera.CameraSubject = CameraStart
            zoomToCam(game.workspace.CameraPart2, 20)
            wait(20)
            zoomToCam(game.workspace.CameraPart, 20)
            wait(20)
        until Opened == false
        -- reset camera back to character
        if game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") then
            game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
            game.Workspace.CurrentCamera.CameraType = "Custom"
        end
    end
end

1 answer

Log in to vote
1
Answered by
WoolHat 53
6 years ago
Edited 6 years ago

I actually encountered this same thing before. Roblox makes you go insane finding this page. Try googling it, it hardly exists.

http://wiki-origin.roblox.com/index.php?title=API:Class/Tween

You should place your neonate into a variable and subsequently play it. Later on, you can reference that same neonate, but instead use Cancel()

Hope this helps.

Ad

Answer this question