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

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

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

✓ Accepted answer

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.

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