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

How to generate a model?

So i am doing a minigame script, trying to have it so it will randomly choose a model with in Lighting but when i look up "ROBLOX Random Lua" or something like that it doesn't return any results that will help me, so i was doing the

if #game.Players:GetChildren() == 5 then
	local message = Instance.new('Message', game.Workspace)
	message.Text = ("Starting Game!")
-- Random Choice Map Here with text spamming through the name of the maps (model name)

Thanks in advance

3 answers

local maps = game.Lighting:GetChildren() -- I would put the maps somewhere more specific, like game.ReplicatedStorage.Maps
local randomMap = maps[math.random(#maps)] -- This is now your randomly selected map
randomMap.Parent = game.Workspace
randomMap:MakeJoints()

1 comment

0

Going to try it , brb

I'm confused by your question... Also messages are outdated and you should probably use GUIs and Server/ReplicatedStorage instead of lighting.

If you want to clone a model into the workspace then:

local maps = {
	"Map name",
	"Other map name"
}

if game.Players.NumPlayers >= 5 then
	local map = game.ServerStorage[maps[math.random(1, #maps)]]:Clone()
	map:MoveTo(Vector3.new(0,0,0)) --Position the model wherever you want.
end

1 comment

0

Trynig this next.

So right now this is my code, was wondering why a message isn't being created when 1 player is in the game. Do i have to test in a full server mode or can i test in solo?

local maps = {
	    "Test"
}
if #game.Players:GetChildren() == 1 then
	local message = Instance.new('Message', game.Workspace)
	message.Text = "Starting Game!"
	wait(1)
	message:destroy()
	local map = game.Lighting[maps[math.random(1, #maps)]]:Clone()
	map:MoveTo(Vector3.new(123, 1.8, 190.5)) --Position the model wherever you want.
end

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