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

How to generate a model?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago
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()
0
Going to try it , brb KnownDev 0 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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
0
Trynig this next. KnownDev 0 — 10y
Log in to vote
0
Answered by 10 years ago

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

Answer this question