What do I want to achieve? Fix my Map loading system
What is the issue? Recently, my map loader has stopped functioning in the way it’s intended to. Everything about it works except for the model being cloned from the folder in Replicated storage, into the Folder on the workspace when the round system starts up (Code example below this description).
When the model is sent from the folder in Replicated storage into the folder on the workspace, none of its children are sent along with it, and it arrives as an empty model. In fact, the empty model was not even visible to me in the workspace until I scripted it to be parented into the workspace specifically.
What solutions have I tried so far? Ive tried adjusting my game’s ModelStreaming settings because I found out that certain settings could prevent the model from being visible, but none of those worked.
Ui botton that triggers the Insertion
local button = script.Parent
local textLabel = button.TextBox
local remoteEvent = game.ReplicatedStorage.Remotes:WaitForChild("LoadMap")
local remoteEvent2 = game.ReplicatedStorage.Remotes:WaitForChild("MapData")
local NotificationHandler = require(game.ReplicatedStorage.NotificationHandler)
button.MouseButton1Click:Connect(function()
NotificationHandler:CreateNotification("default", "Loading Map please wait")
warn("Map loader process began")
local modelIdString = textLabel.Text
local modelId = tonumber(modelIdString)
if modelId then
remoteEvent:FireServer(modelId)
else
NotificationHandler:CreateNotification("alert", "Invalid Model ID:"..modelIdString)
warn("Invalid Model ID in TextLabel:", modelIdString)
end
end)
remoteEvent2.OnClientEvent:Connect(function(MapName)
NotificationHandler:CreateNotification("success", "Successfully loaded "..MapName)
end)
The server side of the Map Insertion
local remoteEvent1 = game.ReplicatedStorage.Remotes:WaitForChild("LoadMap")
local remoteEvent2 = game.ReplicatedStorage.Remotes:WaitForChild("ClearMaps")
local remoteEvent3 = game.ReplicatedStorage.Remotes:WaitForChild("MapData")
local Maps = game.ReplicatedStorage.Maps
local InsertService = game:GetService("InsertService")
local InsertService = game:GetService("InsertService")
remoteEvent1.OnServerEvent:Connect(function(player, modelId)
print(player.Name .. " sent Model ID: " .. modelId)
local success, model = pcall(function()
return InsertService:LoadAsset(modelId)
end)
if success and model then
model.Parent = Maps
wait(1)
local Map = model:GetChildren()[1]
Map.Parent = Maps
model:Destroy()
local MapName = Map:WaitForChild("MapSettings"):WaitForChild("MapDetails"):WaitForChild("MapName").Value
print("Model with ID " .. modelId .. " loaded successfully by " .. player.Name)
remoteEvent3:FireAllClients(MapName)
else
warn("Failed to load model with ID " .. modelId .. ":", model)
end
end)
Part of the round system responsible for loading the map
local random = math.random(1, #maps)
local map = maps[random]:Clone()
map.Name = "MapInsert"
local Name = map:WaitForChild("MapSettings"):WaitForChild("MapDetails"):WaitForChild("MapName")
status.Value = "Map chosen: "..Name.Value
wait(2)
status.Value = "Loading Map, please wait"
The game gets hung up on
local Name = map:WaitForChild(“MapSettings”):WaitForChild(“MapDetails”):WaitForChild(“MapName”)
Because it doesn’t exist in the server’s view, even when it’s imported from a server-side script
Anything I should try?
It would probably be more helpful if I included the entire part of the map loading process
while true do
if forcestart then
for i = 1,10 do -- Intermission time
status.Value = "Match starts in.. "..10-i -- Intermission time
wait(1)
end
local random = math.random(1, #maps)
local map = maps[random]:Clone()
map.Name = "MapInsert"
local Name = map:WaitForChild("MapSettings"):WaitForChild("MapDetails"):WaitForChild("MapName")
status.Value = "Map chosen: "..Name.Value
wait(2)
status.Value = "Loading Map, please wait"
local time = map:WaitForChild("MapSettings"):WaitForChild("Lighting"):WaitForChild("ClockTime")
local MapCreator = map:WaitForChild("MapSettings"):WaitForChild("MapDetails"):WaitForChild("Creators").Value
local MapImage = map:WaitForChild("MapSettings"):WaitForChild("MapDetails"):WaitForChild("MapImage").Value
local Name = map:WaitForChild("MapSettings"):WaitForChild("MapDetails"):WaitForChild("MapName").Value
local MapWater = map:WaitForChild("Water")
local GameWater = game.Workspace.WaterInGame
local OriginalLighting = game.Lighting
local LightingContents = map:WaitForChild("MapSettings"):WaitForChild("Lighting"):WaitForChild("LightingContents") --Model you want to destroy
remoteEvent2:FireAllClients(MapImage, MapCreator, Name)
for k, v in map:GetChildren() do
v:Clone().Parent = workspace.Map
--A small delay so that client and server can catch up and reduce lag.
task.wait(0.1)
end
This is what the Model looks like fully opened. That empty model above is where the map is unpacked for all the game mechanics to work.
When I import the map from the game Console then run the Round manager, it shows the script cannot see the model at all
The map is Technically being inserted into the game correctly because it arrives in the dedicated folder in Replicated storage (Shown in the image below)
This is way too dangerous. If the server takes a ModelId from the client and loads it with InsertService, a hacker can just send a malicious ID. Then, all the scripts inside that model will run on the server. You should never trust the client.
I’m pretty much guessing here, but could the round system be starting too early? Like before the map has been fully loaded/inserted?
If the map contents both exist on the server and the client, then another suspicion I have is maybe the variable is pointing to the wrong map model (or the variable gets updated to something else somewhere in the script).
Alright, so here are a few developments on the issue:
Ive put debugs that print out the names of the children in the map folder in all of the scripts that are related to the Map Loader (Round manager and the model Inserting script)
1 issue is that the ScrollingGrid GUI is still warning me about a yield possible yield in the MapSettings folder, even though it finds it anyway, because that’s where it grabs the map’s name and Thumbnail from.
I don’t know if this is a confirmation that the server is finally finding models inside the Folder now, or just another wall I have to wrap around, I’ve never seen this before
Ive renamed the post so the issue is more straightforward than it used to be, but the issue is still here. Ive tried multiple ideas in the past for days, but haven’t gotten much luck.
Im sure I’ve scripted this correctly, all of my ModelStreaming settings are correct, and im importing the model from a server script triggered by a Remote Event like I should be. Is there anything im missing?
But the Random.New function was still giving me the blues, so I just decided to Jerry-rig the random map process by naming every inserted Model to just “Model”, that way each map appears the same and its a random selection. this eliminates the need for using Math.random or Random.new