Hello! I have a problem, Actually, I want this script to run:
while wait() do
script.Parent.CreatorText.Text = game.Workspace.MapFolder:WaitForChild("Map").Creator.Value
script.Parent.NameText.Text = game.Workspace.MapFolder:WaitForChild("Map").Name.Value
script.Parent.DifficultyText.Text = game.Workspace.MapFolder:WaitForChild("Map").Difficulty.Value
script.Parent.DifficultyText.TextColor3 = game.Workspace.MapFolder:WaitForChild("Map").Color.Value
script.Parent.GamePicture.Image = game.Workspace.MapFolder:WaitForChild("Map").Image.Value
end
But the problem is that in the “MapFolder” Folder, the “Map” is not yet in the file, (it will be cloned later) But then, the script doesn’t execute because it doesn’t find “Map”.
local creator = game.Workspace.MapFolder:FindFirstChild("Map").Creator
if not creator then
repeat wait() until game.Workspace.MapFolder:FindFirstChild("Map").Creator
end
if creator then
while wait() do
script.Parent.CreatorText.Text = game.Workspace.MapFolder:WaitForChild("Map").Creator.Value
script.Parent.NameText.Text = game.Workspace.MapFolder:WaitForChild("Map").Name.Value
script.Parent.DifficultyText.Text = game.Workspace.MapFolder:WaitForChild("Map").Difficulty.Value
script.Parent.DifficultyText.TextColor3 = game.Workspace.MapFolder:WaitForChild("Map").Color.Value
script.Parent.GamePicture.Image = game.Workspace.MapFolder:WaitForChild("Map").Image.Value
end
end
Alternatively if you need to ensure all instances have replicated to a specific client:
-- LocalScript @ game.ReplicatedFirst
game.Loaded:Wait()
-- index anything without WaitForChild, on this client all instances will have replicated with a guarantee
Edit: Just to clarify, this code is meant to be used on the client, out of only 2 possible scenarios (either you need to ensure objects exist on the server or on the client)
this will work for the first, while calling WaitForChild on every object will wait for the objects to load both on the client and server because of how the method works.
There is a very specific case in which this code will solve OP’s issue, by the way they have worded their question, that case is not happening. Using WaitForChild or repeat wait() as previously suggested will ensure the script working no matter what the underlying problem is.