Cannot press play/Play button won't work

Hi, I’m having trouble with some code I made for my friends game. The menu has interchanging cameras, with basic gui. The problem is when I press Play. It doesn’t work. Here’s the code

local content = script.Parent.Content
local cameras = workspace.Cameras
local Camera = workspace.CurrentCamera
local DefaultCFrame = cameras.MainCamera.CFrame
	
local ts = game:GetService("TweenService")
local tweeninf = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)

local function Tween(obj, val)
	local tween = ts:Create(obj,tweeninf,{BackgroundTransparency = val})
	tween:Play()
	tween.Completed:Wait()
end

repeat
	wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until
Camera.CameraType == Enum.CameraType.Scriptable

Camera.FieldOfView = 50

while true do
	Camera.CFrame = cameras.MainCamera.CFrame
	Tween(content, 1)
	wait(10)
	Tween(content, 0)
	Camera.CFrame = cameras.ChangeCamera.CFrame
	Tween(content, 1)
	wait(10)
	Tween(content, 0)
	Camera.CFrame = cameras.ChangeCamera2.CFrame
	Tween(content, 1)
	wait(10)
	Tween(content, 0)
end

local title = script.Parent.Frame
local holder = script.Parent.ButtonHolder

script.Parent.ButtonHolder.Play.Activated:Connect(function()
	script.Parent.sound:Play()
	title:TweenPosition(UDim2.new(0.5, 0, 3, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad)
	holder:TweenPosition(UDim2.new(0.5, 0, 4, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad)
	wait(1.5)
	Camera.CameraType = Enum.CameraType.Custom
	Camera.FieldOfView = 70
	title:Destroy()
	content:Destroy()
	script.Parent.Enabled = false
	script:Destroy()
end)

It may have something to do with the loop, but I’m not sure. How do I fix this? And what would you recommend to be the best alternative for the loop?

I’m just guessing but do you mean the Play button in your game, not the one in Studio?

Where is the script located?
Is it a Local Script or a Server Script?

Try little things like putting a print statement inside each loop to see where the issues are in your script.
Example:

repeat
	wait()
	Camera.CameraType = Enum.CameraType.Scriptable
    print(Enum.CameraType)
until
Camera.CameraType == Enum.CameraType.Scriptable

Also, that repeat loop only fires one time since it’s not in a function or inside another loop so the script will get stuck there if CameraType is never Scriptable.

1 Like

Any code beneath your while true do loop will never run because the loop never ends.
The loop should be the last thing to run in your script so put it at the bottom.

1 Like

Thank you so much! It works now, thank you :slight_smile:

1 Like