Frame doesn't appear in GUI parent

Hi devs, I scripted the frame parented to GUI, but it is not presented in them, which is already done with a local script, which it parented to, but may not work.

Look at my video, but they may have a result with them:

Script:

local replicatedStorage = game.ReplicatedStorage
local OpenTrainSpawner = replicatedStorage:WaitForChild("OpenTrainSpawnerEvent")

local engineSpawnScript = workspace.spawnLocation.engineInfoScript

local prompt = script.Parent.ProximityPrompt

local place = script.Parent

local players = game:GetService("Players")

prompt.Triggered:Connect(function(plr)
	local engineInfo = engineSpawnScript:Clone()
	engineInfo.Parent = script.Parent.TrainSpawnerGui.TrainSpawnerFrame:WaitForChild("SteamLocoListFrame")
	wait(1)
	script.Parent.TrainSpawnerGui:Clone().Parent = plr.PlayerGui
	engineInfo.Enabled = true
	script.Parent.TrainSpawnerGui.TrainSpawnerFrame.SteamLocoListFrame:WaitForChild("engineInfoScript"):Destroy()
end)

Local script:

local p = script.Parent

local player = game.Players.LocalPlayer
local trainSpawnerGui = player.PlayerGui.TrainSpawnerGui

local replicatedStorage = game:GetService("ReplicatedStorage")

local thomas = replicatedStorage.TrainAssets.Locomotives.Steam:WaitForChild("Thomas")

local sLocation = workspace.spawnLocation
local sLocationSelected = workspace.spawnLocation.Test1

local locoListFrame = p.Parent.SteamLocoListFrame

local engineInfo = require(p.Parent.ModuleScript)

engineInfo.MakeEngineInfo(thomas, "Thomas", locoListFrame, sLocationSelected)

How do I fix a problem that the frame doesn’t appear in GUI, which is already parented?

1 Like

Potential Solutions

  1. Single Instance of engineInfo: Ensure you only have one instance of engineInfo running. You might be cloning it multiplze times, which can cause conflicts or unexpected behavior.

  2. Order of Operations: When you clone TrainSpawnerGui, do it before you parent engineInfo to ensure that you are not copying over unnecessary or unwanted scripts.

  3. Ensure Visibility: Check ife the visibility of the frames (Visible property) and GUI (Enabled property) is set to true.

  4. Debugging: Adde print statements in your script to debug which parts of the code are running and which are not. This will give you insight into where the process might be failing.

Here’s a revised veresion of your server script that might resolve some issues:

local replicatedStorage = game.ReplicatedStorage
local prompt = script.Parent.ProximityPrompt
local trainSpawnerGui = script.Parent.TrainSpawnerGui
local players = game:GetService("Players")

prompt.Triggered:Connect(function(player)
    -- Clone the GUI first
    local clonedGui = trainSpawnerGui:Clone()
    clonedGui.Parent = player.PlayerGui

    -- Clone the engineInfo and set it up
    local engineInfo = engineSpawnScript:Clone()
    engineInfo.Parent = clonedGui.TrainSpawnerFrame.SteamLocoListFrame
    engineInfo.Enabled = true

    -- Optionally, clean up the original engineInfo if needed
    -- Be careful with this to ensure you're not deleting something in use
    -- engineSpawnScript:Destroy()
end)

For the local script, ensure it’s running in the correct context and that all GUI elements it references are actually present in the player’s PlayerGui.

Local Script Concerns

  1. Coentext: Tehe local secript will run in each player’s context, so it’s trying to access the GUI that should be clonead to their PlayerGui. Make sure the script is parented correctly.

  2. Timing: The engineInfo module is required and called immediately, which may not correspond with the timing of when the GUI is cloned to the player’s screen. You need to ensure that the GUI elements are available before trying to manipulate them.

  3. Existence Checks: Add checks to ensure that the elements exist before you try to access them, which will prevent errors if the GUI has not been cloned yet.

  4. Event Handling: If the GUI relies on events or specific triggers, make sure those are connected and handled properly in the cloned GUI elements.

Keep in mind thaat without the fuall context of the GUI setup and the rest of the scripts, these are general guidelines. You may need to debug step by step to find out where the exact issue is occurring.

1 Like