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

Would this global function to get maps and spawn them in at random work?

Asked by
IcyEvil 260 Moderation Voter
8 years ago
Edited 8 years ago

This script should globally call maps however I recieve an error when running it.


function _G.GetMaps() -- can now be used in any other server script local maps = game.ServerStorage.Maps:GetChildren() for _,v in pairs(maps)do local randommap = math.random(v) x=randommap:Clone() x.Parent = game.Workspace local m = Instance.new("Message", workspace) m.Text = (x.Name.. " is the current map!" ) wait(3) end end

any and all help appreciated

Error I recieve when running the script

23:35:48.089 - ServerScriptService.GetMaps global function:5: bad argument #1 to 'random' (number expected, got Object)

1 answer

Log in to vote
2
Answered by
1N0body 206 Moderation Voter
8 years ago
Edited 8 years ago

I presume you want a random map to be chosen.

function _G.GetMaps()
    local maps = game.ServerStorage.Maps:GetChildren()
    local randomSelect = math.random(1,#maps)
    local randomMap = maps[randomSelect]

    local x = randomMap:Clone()
    x.Parent = workspace
    local m = Instance.new('Message',workspace)
    m.Text = (x.Name..' is the current map!')
    wait(3) 
-- game:GetService('Debris'):AddItem(m,3), will delete the message too.
end

More Details on map choosing

0
the script works, but I can not remove the Message. IcyEvil 260 — 8y
0
Uncomment line 11 1N0body 206 — 8y
Ad

Answer this question