So I have a 2d Camera Script which works when the tittle screen is closed. It works perfectly fine in Studio but doesn’t work in game 90% of the time.
I made the Camera Script print something at the very start of it to test it out. But in game it prints absolutely nothing almost if it’s not there.
Yes, I published the game and it’s not Team Create so it isn’t a draft either
Here’s how it works in Studio
And here it is in game
Here is the Camera Script itself
local Players = game:GetService("Players")
local player = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):Wait()
local camera = workspace.CurrentCamera
local event = game.ReplicatedStorage.Events:WaitForChild("ChangeCamFromTittle")
player.CharacterAdded:Wait()
player.Character:WaitForChild("HumanoidRootPart")
print("Buckle up!")
event.Event:Wait()
print("Too late, my baby!")
camera.CameraSubject = player.Character.HumanoidRootPart
camera.CameraType = Enum.CameraType.Attach
camera.FieldOfView = 40
local RunService = game:GetService("RunService")
local function onUpdate()
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
camera.CFrame = camera.CFrame:Lerp(CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,35), 0.1)
end
end
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, onUpdate)
Just a suspicion given the context clues provided but I wonder if the player.CharacterAdded:Wait() is causing the thread to yield indefinitely because the CharacterAdded event is occuring before this local script runs.
I can think back to a few instances where I had to call Player:LoadCharacter after connecting Player.CharacterAdded because by the time the function was loaded and connected, the event had already passed.
local Players = game:GetService("Players")
local player = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):Wait()
local camera = workspace.CurrentCamera
local event = game.ReplicatedStorage.Events:WaitForChild("ChangeCamFromTittle")
if not player.Character then
player.CharacterAdded:Wait()
end
player.Character:WaitForChild("HumanoidRootPart")
print("Buckle up!")
event.Event:Wait()
print("Too late, my baby!")
camera.CameraSubject = player.Character.HumanoidRootPart
camera.CameraType = Enum.CameraType.Attach
camera.FieldOfView = 40
local RunService = game:GetService("RunService")
local function onUpdate()
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
camera.CFrame = camera.CFrame:Lerp(CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,35), 0.1)
end
end
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, onUpdate)