In my game I have a title screen that changes the camera to a different view and then changes it to your player when you press play but sometimes the camera doesn’t move with the player so it just gets stuck
local camera = workspace.CurrentCamera
local focus = workspace.Focus
local PlayBtn = script.Parent
local Updates = script.Parent.Parent.TextLabel
function PlaySound()
script.Parent.Sound:Play()
end
script.Parent.MouseButton1Click:connect(PlaySound)
repeat
wait(.1)
camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable
camera.CFrame = focus.CFrame
wait(1)
local function onPlay()
camera.CameraType =Enum.CameraType.Custom
PlayBtn.Visible = false
Updates.Visible = false
end
PlayBtn.Activated:Connect(onPlay)
I just set up your code in the studio. It looks like that the script won’t work if you press the button too early. That’s because of the 1-second wait you put after positioning the camera’s CFrame to the “focus” variable:
As far as the code you’ve provided shows, there’s no reason to be this wait here. Removing it should fix your issue.
It’s because you never returned the camera.CFrame back to the player’s HumanoidRootPart.
Easy fix, but I’m also going to form this so it can be easier to understand.
--- Script ---
local camera = workspace.CurrentCamera -- Camera.
local focus = workspace.Focus -- Part we're using to assign the new CFrame upon joining.
local PlayBtn = script.Parent -- Button the player will press.
local Updates = script.Parent.Parent.TextLabel -- Updates TextLabel.
local Player = game.Players.LocalPlayer -- Assuming this is a LocalScript, we can identify the player this way.
local Character = Player.Character -- We collect the Player's Character.
local HRP = Character:WaitForChild("HumanoidRootPart") -- We wait and for the Character's HumanoidRootPart, and if it's there, locating it was successful.
camera.CFrame = game.Workspace.Focus.CFrame -- We want to collect the new CFrame for the camera as if you put the CameraType to "Scriptable", nothing will happen.
camera.CameraType = Enum.CameraType.Scriptable -- Changes the CameraType to scriptable which will not allow the player to move the camera unless there is a script that allows it to happenm, hence the name 'Scripable.'
PlayBtn.MouseButton1Click:Connect(function() -- The button the player will press.
PlayBtn.Sound:Play() -- Sound will play when pressed.
camera.CameraType = Enum.CameraType.Custom -- Sets CameraType back to Custom so we can change the CFrame.
camera.CFrame = HRP.CFrame -- Reverts the CFrame back to the Character's HumanoidRootPart.
PlayBtn.Visible = false -- Button Disappears.
Updates.Visible = false -- TextLabel Disappears
end)
If this doesn’t work, I can give you a new script.