Camera not working

Hi everyone. I’m trying to make an intro screen for my game and have come across a problem. The camera isn’t moving to a part. (This should be a simple fix and ngl I suck at scripting) Here is the script:

local cam = game.Workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = game.Workspace.IntroCamPart.CFrame

local playbutton = script.Parent
local creditbutton = script.Parent.Parent.Credits
local donobutton = script.Parent.Parent.Donate
local title = script.Parent.Parent.Title
local back = script.Parent.Parent.Back
back.Visible = false

local introUI = script.Parent.Parent
introUI.Enabled = true
introUI.CreditsFrame.Visible = false
introUI.DonoFrame.Visible = false

script.Parent.Parent.Parent["Mute / unmute music"].Enabled = false
script.Parent.Parent.Parent.PassUI.Enabled = false
script.Parent.Parent.Parent.SprintGui.Enabled = false

playbutton.MouseButton1Click:Connect(function()
	
	cam.CameraType = Enum.CameraType.Custom
	
	introUI.Enabled = false
	script.Parent.Parent.Parent["Mute / unmute music"].Enabled = true
	script.Parent.Parent.Parent.PassUI.Enabled = true
	script.Parent.Parent.Parent.SprintGui.Enabled = true
end)

Ty :slight_smile:

1 Like

Any errors?

Maybe:

cam.CFrame = game.Workspace:WaitForChild("IntroCamPart").CFrame
2 Likes

No, there are no errors. This doesn’t work.

Set the cframe before the cameratype

local cam = game.Workspace.CurrentCamera
cam.CFrame = game.Workspace.IntroCamPart.CFrame
cam.CameraType = Enum.CameraType.Scriptable
2 Likes

No this doesn’t seem to be working.

Idk, works for me. It’s in a local script in starterplayerscripts.

1 Like

Oh yea, probably should’ve asked that too.
@DevHelpAccount, is the script local and if so, what’s it’s parent?
I’ve been answered lol

1 Like

@Hqsuperlabgames That’s strange. This is a localscript inside of a textbutton inside of a screengui in startergui but it shouldn’t change how it works.

1 Like

Just in case anyone needs it, here is the full script. (all kinda irrelevant tho-)

local cam = game.Workspace.CurrentCamera
cam.CFrame = game.Workspace.IntroCamPart.CFrame
cam.CameraType = Enum.CameraType.Scriptable

local playbutton = script.Parent
local creditbutton = script.Parent.Parent.Credits
local donobutton = script.Parent.Parent.Donate
local title = script.Parent.Parent.Title
local back = script.Parent.Parent.Back
back.Visible = false

local introUI = script.Parent.Parent
introUI.Enabled = true
introUI.CreditsFrame.Visible = false
introUI.DonoFrame.Visible = false

script.Parent.Parent.Parent["Mute / unmute music"].Enabled = false
script.Parent.Parent.Parent.PassUI.Enabled = false
script.Parent.Parent.Parent.SprintGui.Enabled = false

playbutton.MouseButton1Click:Connect(function()
	
	cam.CameraType = Enum.CameraType.Custom
	
	introUI.Enabled = false
	script.Parent.Parent.Parent["Mute / unmute music"].Enabled = true
	script.Parent.Parent.Parent.PassUI.Enabled = true
	script.Parent.Parent.Parent.SprintGui.Enabled = true
end)

creditbutton.MouseButton1Click:Connect(function()
	back.Visible = true
	introUI.CreditsFrame.Visible = true
	creditbutton.Visible = false
	playbutton.Visible = false
	donobutton.Visible = false
	title.Visible = false
	
	back.MouseButton1Click:Connect(function()
		back.Visible = false
		introUI.CreditsFrame.Visible = false
		creditbutton.Visible = true
		playbutton.Visible = true
		donobutton.Visible = true
		title.Visible = true
	end)
	
end)

donobutton.MouseButton1Click:Connect(function()
	back.Visible = true
	introUI.DonoFrame.Visible = true
	creditbutton.Visible = false
	playbutton.Visible = false
	donobutton.Visible = false
	title.Visible = false
	
	back.MouseButton1Click:Connect(function()
		back.Visible = false
		introUI.DonoFrame.Visible = false
		creditbutton.Visible = true
		playbutton.Visible = true
		donobutton.Visible = true
		title.Visible = true
	end)
	
end)

Try adding this to the very beginning:

game:GetService("RunService").Heartbeat:Wait()


(Image from the task scheduler documentation)

As you can see, Heartbeat is the very last in this, after all rendering and simulation.
That means it will force the script to run after we’re certain the camera has actually loaded in, by waiting for a frame to be rendered.

I did this and it worked while in a textbutton in a screengui:

game:GetService("RunService").Heartbeat:Wait()

local cam = game.Workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = game.Workspace:WaitForChild("IntroCamPart").CFrame
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.