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

Maps are removed from ServerStorage?

Asked by
Spoookd 32
8 years ago

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

Log in to vote
2
Answered by
Vexture 179
8 years ago

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. :^)

0
Only if FE is enabled. FE is disabled for him. User#11440 120 — 8y
0
What? I thought even if FE is enabled, locals aren't allowed to use serverStorage theCJarmy7 1293 — 8y
0
Even if filtering is enabled, it still won't allow a local script to access server storage. Vexture 179 — 8y
0
So what do I do then? Spoookd 32 — 8y
View all comments (5 more)
0
Write the script inside a normal server script instead of a local script or put the maps inside replicatedstorage LifeInDevelopment 364 — 8y
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) Spoookd 32 — 8y
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) Spoookd 32 — 8y
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) Vexture 179 — 8y
0
I am using it in a local script Spoookd 32 — 8y
Ad

Answer this question