I have an issue that’s easily replicable but i can’t seem to figure out how to fix, I have a script that creates a new camera and a new Model and inserts them inside of a viewport frame inside of starterGui, when i run the script it doesnt initially work, But when i exit workspace to go into the script editor everything loads.
This is a copy of the script :
local RunService = game:GetService(“RunService”)
script.Parent.MouseClick:Connect(function(player)
for _, v in pairs(game.Workspace.Poser:GetChildren()) do
if v:IsA(“Accessory”) or v:IsA(“BodyColors”) or v:IsA(“Shirt”) or v:IsA(“Pants”) then
v:Destroy()
end
end
local player = game.Players:FindFirstChild(game.Workspace.Ready.Player.Value)
if player then
for _, v in pairs(player.Character:GetChildren()) do
if v:IsA("Accessory") or v:IsA("BodyColors") or v:IsA("Shirt") or v:IsA("Pants") then
local he = v:Clone()
he.Parent = game.Workspace.Poser
end
end
end
wait(.1)
local newcam = Instance.new("Camera")
newcam.CFrame = script.Parent.Parent.CFrame
newcam.Parent = game.StarterGui.SurfaceGui.ViewportFrame
local viewportFrame = game.StarterGui.SurfaceGui.ViewportFrame
if viewportFrame then
RunService.Heartbeat:Wait(1)
viewportFrame.CurrentCamera = newcam
else
warn("Viewport frame not found.")
end
local clone = game.Workspace.Poser:Clone()
clone.Parent = game.StarterGui.SurfaceGui.ViewportFrame
end)