Camera Position Problem

hey there developers! soo umm, i tried to make the main menu in my game with camera, it works perfectly but, it didn’t change the camera position

and heres some camera position’s
the main camera :


the store camera :

and heres are the script

Local Script :

local plr = game.Players.LocalPlayer

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


local mouse = plr:GetMouse()


local camera = workspace.CurrentCamera

local menuCamera = workspace.MenuComponents
local startCamera = menuCamera:WaitForChild("CameraStartPosition")
local shopCamera = menuCamera:WaitForChild("CameraShopPosition")

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = startCamera.CFrame


local tweenService = game:GetService("TweenService")
local contentProvider = game:GetService("ContentProvider")

local guiHandler = plr.PlayerScripts:WaitForChild("GuiHandler")

local mainMenuGui = script.Parent

local mainMenu = mainMenuGui:WaitForChild("MainMenu")

local logoMenu = mainMenu:WaitForChild("Logo")

local play = mainMenu:WaitForChild("Play")
local playBtn = play:WaitForChild("PlayButton")

local setting = mainMenu:WaitForChild("Setting")
local settingBtn = setting:WaitForChild("SettingButton")

local store = mainMenu:WaitForChild("Store")
local storeBtn = store:WaitForChild("StoreButton")

local inv = mainMenu:WaitForChild("Inventory")
local invBtn = inv:WaitForChild("InventoryButton")

local loadingScreenBG = mainMenuGui:WaitForChild("LoadingScreenBackground")

local logo = loadingScreenBG:WaitForChild("Logo")
local uiGradient = logo:WaitForChild("UIGradient")

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

repeat wait() until game:IsLoaded()

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

local assets = game:GetDescendants()
for i = 1, #assets do
	local asset = assets[i]

	loadingText.Text = "Loading Assets...["..i.."/"..#assets.."]"
	clippingFrame.Size = UDim2.new(i/#assets, 0, 1, 0)
	uiGradient.Offset = Vector2.new(i/#assets, 0)
	contentProvider:PreloadAsync({asset})
end


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)
loadingText: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
local field = nil

if field == nil then
	field = Instance.new("ForceField")
	field.Parent = char
end

playBtn.MouseButton1Click:Connect(function()

	if playButtonClicked then return end
	playButtonClicked = true

	play:TweenPosition(UDim2.new(0.5, 0, 1.5, 0), Enum.EasingDirection.In, Enum.EasingStyle.Back, 1.5, true)

	setting:TweenPosition(UDim2.new(0.5, 0, -0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2, true)

	store:TweenPosition(UDim2.new(-1, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2, true)

	inv:TweenPosition(UDim2.new(2, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2, true)

	logoMenu:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Back, 2, true)
	
	wait(3)
	
	if guiHandler.Disabled == true then
		guiHandler.Disabled = false
	end
	
	if field ~= nil then
		char.ForceField:Destroy()
		field = nil
	end

	char.HumanoidRootPart.Anchored = false
	
	camera.CameraType = Enum.CameraType.Custom
	
	mainMenuGui:Destroy()
end)

local storeButtonClicked = false

storeBtn.MouseButton1Click:Connect(function()
	
	if storeButtonClicked then return end
	storeButtonClicked = true
	
	play:TweenPosition(UDim2.new(0.5, 0, 1.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2, true)

	setting:TweenPosition(UDim2.new(0.5, 0, -0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2, true)

	store:TweenPosition(UDim2.new(2, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 3, true)

	inv:TweenPosition(UDim2.new(2, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 2, true)

	logoMenu:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Back, 2, true)
	
	wait(3)
	
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = shopCamera.CFrame
	
	store:TweenPosition(UDim2.new(3, 0, 0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quint, 5, true)
	
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)

playBtn.MouseLeave:Connect(function()

	hoverOffButton(playBtn)
end)

storeBtn.MouseEnter:Connect(function()

	hoverOnButton(storeBtn)
end)

storeBtn.MouseLeave:Connect(function()

	hoverOffButton(storeBtn)
end)

settingBtn.MouseEnter:Connect(function()

	hoverOnButton(settingBtn)
end)

settingBtn.MouseLeave:Connect(function()

	hoverOffButton(settingBtn)
end)

invBtn.MouseEnter:Connect(function()

	hoverOnButton(invBtn)
end)

invBtn.MouseLeave:Connect(function()

	hoverOffButton(invBtn)
end)

(and yes i stole it from free model:P, but i change some script)
can someone please help me fix this?, thank you!. And tell me if theres a problem

try removing the camera.CameraType = Enum.CameraType.Scriptable line

still doesnt work, even tho theres no error

Are you getting anything in your output at all?


theres literally nothing on my output

Your issue is here:

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)

You’re changing the cameras CFrame with RunService, meaning when you attempt to change the cameras CFrame once more with MouseButton1Click, it’s going to get hung up as we’re seeing here. If you were to comment out that line or add logic to stop or edit the originalCFrame variable upon clicking that button, this would probably work.

it work!, thank you so much for the help!!

1 Like