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

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

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

✓ Accepted answer

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

2 comments

0

the script works, but I can not remove the Message.

0

Uncomment line 11

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