Train Spawner GUI is look weird

Hello guys, so I have scripted for a train spawner GUI, in a train list, but it seems to have gone missing.

It looked kinda weird when I scripted it, but how is infinite yield possible on ServerStorage?

LocalScript:

local p = script.Parent

local serverStorage = game:GetService("ServerStorage")

local train = serverStorage:WaitForChild("Thomas")
local testOne = game.Workspace:WaitForChild("Test1")

local locoListFrame = p.Parent.SteamLocoListFrame

local engineInfo = require(p.Parent.ModuleScript)

engineInfo.MakeEngineInfo(train, "Hello Word", locoListFrame, testOne)

After I looked in ServerStorage, Idk how it deleted the objects itself. But how do I make a train spawner GUI without the train disappearing at least?

Hello there. This is a typical issue when replication comes into play. ServerStorage is inaccessible via clients because there may be objects that must be seen by the server only. You can use the ReplicatedStorage service, which acts the same and is accessible by both clients and the server.

As for the UI, you shall delete the lines that search for the object if it is necessary to observe the UI occur on the screen.

Thanks, Programmer. So, I shall create the object value named “SpawnLocationSelected”, but the value does not have the CFrame value. I should create the CFrame value inside of the actual value, but the train is positioned at the centre of the baseplate (spawn part).

Capture d’écran 2023-11-18 104425

Local Script:

local openTrainSpawnerEvent = game.ReplicatedStorage:WaitForChild("OpenTrainSpawnerEvent")

openTrainSpawnerEvent.OnClientEvent:Connect(function(sLocation, sLocationPart)
	script.Parent.TrainSpawnerFrame.Visible = true
	script.Parent.TrainSpawnerFrame.SpawnLocationSelected.Value = sLocation
	
	if script.Parent.TrainSpawnerFrame.SpawnLocationSelected.Value then
		script.Parent.TrainSpawnerFrame.SpawnLocationSelected.CFrameValue.Value = sLocationPart.CFrame
	end
end)

The local script inside of the frame:

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 sLocationSelected = trainSpawnerGui.TrainSpawnerFrame:WaitForChild("SpawnLocationSelected")
local sLocationCFrame = sLocationSelected:WaitForChild("CFrameValue").Value

local locoListFrame = p.Parent.SteamLocoListFrame

local engineInfo = require(p.Parent.ModuleScript)

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

How do I fix that the train will centre at the part’s position?

1 Like

If I interpreted it correctly, you want the train to spawn on top of the spawn location, but it spawns in the middle of the baseplate, where the spawn location is also in the middle but on top of the baseplate, right?

You might wanna get the model’s smallest box which contains all of its objects and then set the train’s position with its size accordingly.

Update the code snippet which sets the coordinates of the train. You should be doing it like the following:

local trainModel = "Train Location"
local smallestBox = trainModel:GetExtentsSize()
trainModel:PivotTo(sLocationCFrame + Vector3.new(0, smallestBox.Y / 2, 0))
1 Like