New instances only load when I leave workspace

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”)

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

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


local newcam ="Camera")
newcam.CFrame = script.Parent.Parent.CFrame
newcam.Parent = game.StarterGui.SurfaceGui.ViewportFrame

local viewportFrame = game.StarterGui.SurfaceGui.ViewportFrame
if viewportFrame then
	viewportFrame.CurrentCamera = newcam
	warn("Viewport frame not found.")

local clone = game.Workspace.Poser:Clone()
clone.Parent = game.StarterGui.SurfaceGui.ViewportFrame


The StarterGui is what gets copied to your PlayerGui when your character starts. I think you would want to use the PlayerGui instead. You might also need to set the ResetOnSpawn to false in the SurfaceGui if you want the changes to persist when your player respawns.

1 Like

It’s supposed to be viewed by all the players, and i mean it does work, but i need to leave workspace

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.