Why am I getting this error?

Hey, I need help with this menu that I’m doing and I don’t know why stuff is erroring.

Screenshot of error:
image

Im so confused why its erroring because its at the right place.
image

The script incase you need it:


local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart").Anchored = true


local mouse = plr:GetMouse()


local camera = workspace.CurrentCamera

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace.MenuComponents.CameraStartPosition.CFrame


local tweenService = game:GetService("TweenService")


local mainMenuGui = script.Parent


local mainMenuBG = mainMenuGui:WaitForChild("MainMenuBackground")

local playBtn = mainMenuBG:WaitForChild("PlayButton")
local creditsBtn = mainMenuBG:WaitForChild("CreditsButton")

local creditsBG = mainMenuBG:WaitForChild("CreditsBackground")


local loadingScreenBG = mainMenuGui:WaitForChild("LoadingScreenBackground")

local logo = loadingScreenBG:WaitForChild("Logo")

local loadingBarBG = loadingScreenBG:WaitForChild("LoadingBarBG")
local clippingFrame = loadingBarBG:WaitForChild("ClippingFrame")
local loadingBar = clippingFrame:WaitForChild("LoadingBar")


clippingFrame.Size = UDim2.new(0, 0, 1, 0)

clippingFrame:TweenSize(UDim2.new(1, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 5)


clippingFrame:GetPropertyChangedSignal("Size"):Connect(function()	
	
	loadingBar.Size = UDim2.new(1/clippingFrame.Size.X.Scale, 0, 1, 0)
end)


repeat wait() until clippingFrame.Size == UDim2.new(1, 0, 1, 0)


local loadingScreenFade = tweenService:Create(loadingScreenBG, TweenInfo.new(3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {BackgroundTransparency = 1})
loadingScreenFade:Play()

logo:TweenPosition(UDim2.new(0.5, 0, -0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2)
loadingBarBG:TweenPosition(UDim2.new(0.5, 0, 1.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2)



local originalCFrame = camera.CFrame
local scaleFactor = 1000


game:GetService("RunService").RenderStepped:Connect(function()
	
	
	local centreOfScreen = Vector2.new(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2)
	
	local mouseDistanceFromCentre = Vector3.new((-mouse.X - centreOfScreen.X) / scaleFactor, (mouse.Y - centreOfScreen.Y) / scaleFactor, 0)
	
	
	camera.CFrame = originalCFrame * CFrame.new(originalCFrame.LookVector + mouseDistanceFromCentre)
end)


local playButtonClicked = false

playBtn.MouseButton1Click:Connect(function()
	
	if playButtonClicked then return end
	playButtonClicked = true
	
	
	creditsBG:TweenPosition(UDim2.new(-0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true)
	
	mainMenuBG:TweenPosition(UDim2.new(-1, 0, 0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 3, true)
	
	
	wait(3)
	
	
	char.HumanoidRootPart.Anchored = false
	char.HumanoidRootPart.CFrame = workspace.MenuComponents.SpawnPart.CFrame
	
	camera.CameraType = Enum.CameraType.Custom
	
	mainMenuGui:Destroy()
end)


local creditsOpen = false

creditsBtn.MouseButton1Click:Connect(function()
	
	
	if playButtonClicked then return end
	
	
	if creditsOpen then
		creditsBG:TweenPosition(UDim2.new(-0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true)
		
	else
		creditsBG:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 1, true)
	end
	
	creditsOpen = not creditsOpen
end)


local function hoverOnButton(btn)
	
	if playButtonClicked then return end
	
	local colourDarken = tweenService:Create(btn, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {ImageColor3 = Color3.fromRGB(221, 221, 221)})
	colourDarken:Play()
end

local function hoverOffButton(btn)
	
	if playButtonClicked then return end
	
	local colourNormal = tweenService:Create(btn, TweenInfo.new(0.1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {ImageColor3 = Color3.fromRGB(255, 255, 255)})
	colourNormal:Play()
end


playBtn.MouseEnter:Connect(function()
	
	hoverOnButton(playBtn)
end)
creditsBtn.MouseEnter:Connect(function()
	
	hoverOnButton(creditsBtn)
end)

playBtn.MouseLeave:Connect(function()
	
	hoverOffButton(playBtn)
end)
creditsBtn.MouseLeave:Connect(function()
	
	hoverOffButton(creditsBtn)
end)```
1 Like

It seems to be correct. Is the part Anchored and perhaps put a WaitForChild?

That error means that CameraStartPosition didn’t exist when the script ran. Either it was removed, you have another thing called MenuComponents, or it was still loading when the script ran. If it was removed, check that it’s either CanCollide true or Anchored, and check that it’s Archivable. If there’s something else called MenuComponents, just rename either one. If the part was just loading when the script ran or something, put use a WaitForChild like you did for most other elements.

8 Likes

When I added the menu to a baseplate it works but not at the game I’m developing for.

It might be unanchored or maybe add “WaitForChild” if you haven’t or maybe it is parented to a different child in the model

1 Like

Yes it’s both anchored and on WaitForChild.

Is archivable on the part set to true?

1 Like

I found the problem. It was because StreamingEnabled was on. Thank you for trying to help!

1 Like

Oh no problem, glad it’s working now!

1 Like