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

How to make it so that when I click a button it stops this script from running?

Im trying to make it so that when I press a play button it makes this script stop and makes the camera angle go back to following the player. Please help ive been at this for a while and so far have had numerous unsuccessful attempts at stopping it.

wait(0.5)
--Services
local Tween = game:GetService("TweenService")

--Camera Tweens

local Cam = workspace.CurrentCamera
local CamPoints = workspace:WaitForChild("CameraPoints")
local Screen = script.Parent.Start
local PlayBtn = Screen.PlayBtn

local function TweenCameraPos(Point, Speed)
	Tween:Create(Cam, TweenInfo.new(Speed, Enum.EasingStyle.Linear), {CFrame = Point.CFrame}):Play()
end

Cam.CameraType = Enum.CameraType.Scriptable
Cam.FieldOfView = 50


while true do
	Cam.CFrame = CamPoints:FindFirstChild("1").CFrame
	TweenCameraPos(CamPoints:FindFirstChild("2"), 4)
	wait(4)
	Cam.CFrame = CamPoints:FindFirstChild("2").CFrame
	TweenCameraPos(CamPoints:FindFirstChild("3"), 4)
	wait(4)
	Cam.CFrame = CamPoints:FindFirstChild("3").CFrame
	TweenCameraPos(CamPoints:FindFirstChild("4"), 4)
	wait(4)
	Cam.CFrame = CamPoints:FindFirstChild("4").CFrame
	TweenCameraPos(CamPoints:FindFirstChild("1"), 4)
	wait(4)
end

2 comments

0

script.Disabled = true lol, but i wonder if it work...

0

I tried that already still didnt work :(

2 answers

✓ Accepted answer

Like this

wait(0.5)
--< Services
local PlayerService = game:GetService("Players")
local TweenService = game:GetService("TweenService")

--< Variables
local Player = PlayerService.LocalPlayer -- LocalScript only
local PlayerGui = Player:WaitForChild('PlayerGui')

local CurrentCamera = workspace.CurrentCamera
local CameraPoints = workspace:WaitForChild("CameraPoints")
local Screen = PlayerGui:WaitForChild('ScreenGui')
local PlayBtn = Screen.PlayBtn

local Intro = {
	Atv = false, Tween = nil, Pos = 0
}

--< Functions
function Intro:Stop()
	self.Tween:Cancel()
	self.Atv = false
	self.Pos = 0
	CurrentCamera.CameraType = Enum.CameraType.Custom
	CurrentCamera.FieldOfView = 70
	CurrentCamera.CameraSubject = Player.Character.Humanoid
end

function Intro:Start()
	self.Atv = true
	CurrentCamera.CameraType = Enum.CameraType.Scriptable
	CurrentCamera.FieldOfView = 50
	while self.Atv and wait() do
		for i = 1, (#CameraPoints:GetChildren() / 2) do
			local Cam1 = CameraPoints:GetChildren()[i + self.Pos]
			self.Pos = self.Pos + 1
			local Cam2 = CameraPoints:GetChildren()[i + self.Pos]
			CurrentCamera.CFrame = Cam1.CFrame
			self.Tween = TweenService:Create(CurrentCamera, TweenInfo.new(4), {CFrame = Cam2.CFrame})
			self.Tween:Play()
			wait(4)
			if not self.Atv then
				break
			end
		end
		self.Pos = 0
	end
end

--< Events
PlayBtn.MouseButton1Click:Connect(function()
	Intro:Stop()
end)

Intro:Start()

1 comment

0

Thanks :)

Have you tried using tween:Pause() and then disabling the script?

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