Hi all!
I am working on a camera script and i have a part called “Cam” where the camera should be. When i try to run everything it says that “Cam is not a part of Workspace.studio”, even though it is. What’s the problem here?
local camera = game.Workspace.Camera
local studio = game.Workspace.Studio
game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function(pet)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = studio.Cam.CFrame
If this script is run before the game fully loads, workspace.Studio may not exist at that point in the code due to a race condition.
To fix this, you could try replacing local studio = game.Workspace.Studio with local studio = workspace:WaitForChild("Studio") so the game will wait for that object to load (see Instance:WaitForChild)
If that doesn’t work, try printing studio to see if you are referencing the right object.
local Camera = workspace.CurrentCamera
local Studio = workspace.Studio
game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function(pet)
wait()
Camera.CFrame = Studio.Cam.CFrame
local Workspace = game:GetService("Workspace");
local camera = Workspace:FindFirstChild("CurrentCamera")
local studio = Workspace.Studio
local TweenService = game:GetService("TweenService");
local tInfo = TweenInfo.new(0);
game.ReplicatedStorage.HatchEgg.OnClientEvent:Connect(function(pet)
local goal = {CFrame = studio.Cam.CFrame;}
local tween = TweenService:Create(camera,tInfo,goal)
camera.CameraType = Enum.CameraType.Scriptable
tween:Play()
end)
if it doesn’t work, change a part of the code with OnServerEvent
And if it still doesn’t work, I don’t know what other solution to give you