Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Maps are removed from ServerStorage?

I am trying to make it so when 2 players are in the game, maps will be chosen out of the ServerStorage and cloned into workspace and the players will go there. But when I test it, ServerStorage is empty, which causes it to not work. Why does it become empty?

maps = game.ServerStorage:GetChildren()
local player = game:GetService"Players".LocalPlayer
local guis = player:WaitForChild"PlayerGui"


while wait(.5) do
    if game.Players.NumPlayers >= 2 then
        guis.ScreenGui.Frame.Map.Visible = false
        guis.ScreenGui.Frame.Madeby.Visible = false
        wait(3)
        ranmap = math.random(1, #maps)
        guis.ScreenGui.Frame.Visible = true
        guis.ScreenGui.Frame.Beingchosen.Visible = true
        wait(1)
        chosen = maps[ranmap]
        chosenclone = chosen:Clone()
        chosenclone.Parent = game.Workspace
        guis.ScreenGui.Frame.Map.Visible = true
        guis.ScreenGui.Frame.Madeby.Visible = true
        guis.ScreenGui.Frame.Madeby.Text = "Map is " .. chosen.Name .. " By: Spoookd"
        wait(5)     
        spawn = chosenclone.SpawnPoint
        for i,v in pairs(game.Players:GetPlayers()) do
            name = v.Name
            check = game.Workspace:FindFirstChild(name)
            if check then
                checkHumanoid = check:FindFirstChild("Humanoid")
                if checkHumanoid then
                    check:MoveTo(spawn.Position)
                end
            end
            guis.ScreenGui.Frame.Visible = false
        end
    else
        guis.ScreenGui.Frame.Visible = false--I moved this
        h = Instance.new("Hint", game.Workspace)
        h.Text = "You need more than 1 player to play."
    end
end

1 answer

It looks like you're using a LocalScript, based on the fact that you're getting LocalPlayer. ServerStorage can only be accessed by Normal Scripts located inside the Workspace or ServerScriptService. I hope this helps. :^)

9 comments

0

Only if FE is enabled. FE is disabled for him.

0

What? I thought even if FE is enabled, locals aren't allowed to use serverStorage

0

Even if filtering is enabled, it still won't allow a local script to access server storage.

0

So what do I do then?

0

Write the script inside a normal server script instead of a local script or put the maps inside replicatedstorage

0

Well now I just kept the local script in replicatedfirst and out the maps in replicated storage and this comes up: 17:36:17.662 - ReplicatedFirst.LocalScript:11: bad argument #2 to 'random' (interval is empty)

0

also if I put it into a normal script and put it into workspace, an error comes up: Workspace.Script:3: attempt to index global 'player' (a nil value)

0

then you didn't randomly select your map properly; also, the global player thing is because you can't define "game.Players.LocalPlayer" in a server script, only in local scripts. try getting the player with game.Players.PlayerAdded:connect(function(player) --[[do yourstuff here]]-- end)

0

I am using it in a local script

This discussion is preserved as it was. New answers, comments, and votes are closed.