Camera script not working [[[NOT SOLVED]]]

I have a main menu camera that is supposed to change what the player sees but it doesn’t work.

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Camera = workspace.CurrentCamera

repeat task.wait() until game:IsLoaded()
repeat task.wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.MainMenu.CameraMenu.CFrame

there are no errors in the output

It is a local script in the startergui and it works in studio, but not client

1 Like

A Couple of Questions,

  • Why are you Using :IsLoaded on a Camera?

  • Why are you Using a Loop?

Just Do this:

Player = game.Players.LocalPlayer
Character = Player.Character
Camera = workspace.CurrentCamera

MainMenu = workspace.MainMenu

wait() -- This simple wait is important

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = MainMenu.CameraMenu.CFrame
1 Like

don’t remember task.wait() wait() is deprecated
also this script doesn’t work at all

1 Like

The wait() inside the script is there because the Player hasn’t joined yet when the script runs, adding that wait will prevent the error

Are you sure this script is Inside StarterGui?

1 Like

Yes.
Screen Shot 2022-11-08 at 8.30.48 AM

Yes, im just saying use task.wait() instead.

1 Like

So i tested the script, Yes, it indeed does work

Ah, wait, I think its because I used task.wait()

It works in studio, but not client…

Should work for every client, its a LocalScript

if you want, you can change the wait

Well, its still not working. I dont know why.

Oddly enough, it works for me, so i have no idea what you’re doing


studio

roblox player doesn’t work, but it has the play button and it works but whenever I kill myself it puts my camera to main menu

Weird, because in the old script it worked but I updated the main menu and now it doesn’t work…

Looking at it, appears normal, i’m not sure, but Try this:

Players = game:GetService("Players")
Character = Players.LocalPlayer.Character
Camera = workspace.CurrentCamera

PlayerIsReady = false

MainMenu = workspace.MainMenu

while wait() and PlayerIsReady == false do
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = MainMenu.CameraMenu.CFrame
end


Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		PlayerIsReady = true
	end)
end)

Is there a way to print out the results?

edit: it works, but whenever I press the play button it doesn’t work
the play button does this:

script.Parent.MouseButton1Click:Connect(function(player)
	script.Parent.Parent.Parent:Destroy()
	local Player = game.Players.LocalPlayer
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Camera = workspace.CurrentCamera

	Camera.CameraType = Enum.CameraType.Custom
	game.StarterPack.AudioVisualizer.Enabled = false
	game.StarterPack.AudioVisualizer:Destroy()
	workspace.MainMenuSong:Stop()
end)

Cant you use pcall for that?

local Success, Result = pcall(function()
-- Code here
end)

if Success then
print(Result)


end

I dont know why it does this, it just clips to the player for a millisecond then goes back to the main menu.

edit: the

code now is this:

script.Parent.MouseButton1Click:Connect(function(player)
	script.Parent.Parent.Parent:Destroy()
	local Player = game.Players.LocalPlayer
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Camera = workspace.CurrentCamera

	Camera.CameraType = Enum.CameraType.Custom
	game.StarterPack.AudioVisualizer.Enabled = false
	game.StarterPack.AudioVisualizer:Destroy()
	game.StarterGui.Camera:Destroy()
	workspace.MainMenuSong:Stop()
	local PlayerIsReady = true

	local MainMenu = workspace.MainMenu

	while wait() and PlayerIsReady == true do
		Camera.CameraType = Enum.CameraType.Custom
		Camera.CFrame = MainMenu.CameraMenu.CFrame
	end
end)

whenever it gets pressed a whole lot of bugs happen, I cant explain them all

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local PlayerIsReady = false

while wait() and PlayerIsReady == false do
		Camera.CameraType = Enum.CameraType.Custom
		Camera.CFrame = MainMenu.CameraMenu.CFrame
end

Players.PlayerAdded:Connect(function()
PlayerIsReady = true
end)


script.Parent.MouseButton1Click:Connect(function(player)
	script.Parent.Parent.Parent:Destroy()
	

	Camera.CameraType = Enum.CameraType.Custom
	game.StarterPack.AudioVisualizer.Enabled = false
	game.StarterPack.AudioVisualizer:Destroy()
	game.StarterGui.Camera:Destroy()
	workspace.MainMenuSong:Stop()
	

	local MainMenu = workspace.MainMenu

	
end)

This still breaks and the camera script doesn’t work anymore because of this

@ASTROCPF
I appear to have fixed it:

local MainMenu = workspace.MainMenu
local Camera = workspace.CurrentCamera
local PlayerIsReady = false

co = coroutine.create(function()
while PlayerIsReady == false do
	wait()
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = MainMenu.CameraMenu.CFrame
end
end)

if PlayerIsReady == false then
coroutine.resume(co)
else
coroutine.close(co)
end

script.Parent.MouseButton1Click:Connect(function(player)
	--script.Parent.Parent.Parent:Destroy()

PlayerIsReady = true
	Camera.CameraType = Enum.CameraType.Custom
	--game.StarterPack.AudioVisualizer.Enabled = false
	--game.StarterPack.AudioVisualizer:Destroy()
	
	--workspace.MainMenuSong:Stop()


	

script:Destroy()
end)

You’re not checking if the workspace is loaded before running the rest of your script.

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Camera = workspace.CurrentCamera

repeat task.wait() until workspace:IsLoaded()

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = workspace.MainMenu.CameraMenu.CFrame
1 Like