Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Getting model's name from ServerStorage?

Asked by 7 years ago
Edited 7 years ago

So I'm trying to make a basic map selector gui. At the moment I'm only trying to get all the maps' names in ServerStorage which are in a Folder to print. (Everything works in play-solo in-studio, but not online or in test server) I have a local script in a gui which fires a remote event in a server script located in the ServerScriptService.

This is what I have in the server script:

local replicatedStorage = game:GetService("ReplicatedStorage")
local networking = replicatedStorage:WaitForChild("networking")
local remoteFunctions = networking:WaitForChild("remoteFunctions")
local remoteEvents = networking:WaitForChild("remoteEvents")
local remote = remoteEvents:WaitForChild("remote")
local remote2 = remoteEvents:WaitForChild("makeTrainerGuiVisible")
local remote3 = remoteEvents:WaitForChild("getMaps")
local serverStorage = game:GetService("ServerStorage")
local mapFolder = serverStorage:WaitForChild("mapFolder")

remote3.OnServerEvent:connect(function(plr)
    local player = plr
    local mapList = {}
    local mapTable = mapFolder:GetChildren()
    for i = 1, #mapTable  do
        table.insert(mapList, mapTable[i])
    end
    print (mapList[1])

    remote3:FireClient(player, mapList)
end)

The server script successfully prints the name of the maps, but the local script doesn't print anything. Why would that be, what can I do to fix this?

Here's what's in the local script:

remote3.OnClientEvent:connect(function(mapList)
    for i, v in pairs(mapList) do
        print(i..'-'..tostring(v))
    end
end)

1 answer

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
7 years ago

Nothing in ServerStorage can be accessed by the client. None of it exists on the client, it is never replicated. You can't find it. If you put it in ReplicatedStorage, however, then it does replicate and the client is able to access it.

I don't know why you're trying to pass server-sided objects to the client, but you can send a table with just the names of all of the maps instead.

0
Ah.. crap, of course... Many thanks! SketchTitan 40 — 7y
Ad

Answer this question