I tried to make it so when you press the play button gui it changes your camera from the main menu to the character but its not working i’ve tried changing the order that didn’t work and then i looked on the forums, and the Camera.CameraSubject but still couldn’t find anything here is my code:
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart").Anchored = true
local mouse = plr:GetMouse()
local humanoid = char:FindFirstChildOfClass("Humanoid")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace.MenuComponents.CameraStartPosition.CFrame
local tweenService = game:GetService("TweenService")
local playBtn = script.Parent:WaitForChild("PlayButton"):WaitForChild("TextButton")
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
print("clicked")
wait(3)
char.HumanoidRootPart.Anchored = false
char.HumanoidRootPart.CFrame = workspace.MenuComponents.SpawnPart.CFrame
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = char:FindFirstChild("Humanoid")
end)
if playButtonClicked then return 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), {BackgroundColor3 = Color3.fromRGB(103, 209, 16)})
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), {BackgroundColor3 = Color3.fromRGB(103,209,16)})
colourNormal:Play()
end
playBtn.MouseEnter:Connect(function()
hoverOnButton(playBtn)
end)
playBtn.MouseLeave:Connect(function()
hoverOffButton(playBtn)
end)