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

Why won't this script Fire?

Asked by 10 years ago

Hi, Here is the script that won't fire or work at all.

Map1of4 = game.ServerStorage.Map1
Map2of4 = game.ServerStorage.Map2
Map3of4 = game.ServerStorage.Map3
Map4of4 = game.ServerStorage.Map4
game.Players.PlayerAdded:connect(function(plr)
    math.random(1,4)
    if 1 then
        Map1of4:clone(game.Workspace)
    end
    if 2 then
        Map2of4:clone(game.Workspace)
    end
    if 3 then
        Map3of4:clone(game.Workspace)
    end
    if 4 then
        Map4of4:clone(game.Workspace)
    end
end)

I have been trying to figure out whats going on here because I'm not getting any errors. Please help!!! THANKS!!!!

2 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
local maps = game.ServerStorage["Maps"]:GetChildren() -- put all your maps in a Model named "Maps" in ServerStorage

random table item http://wiki.roblox.com/index.phptitle=Function_dump/Mathematical_functions#math.random

Note to devs: Links that span two lines don't work.

game.Players.PlayerAdded:connect(function() 
    maps[math.random(1, #maps)]:Clone().Parent = Workspace
end)

Yours fixed;

Map1of4 = game.ServerStorage.Map1
Map2of4 = game.ServerStorage.Map2
Map3of4 = game.ServerStorage.Map3
Map4of4 = game.ServerStorage.Map4
game.Players.PlayerAdded:connect(function()
    local randy = math.random(1,4) -- You need a variable to use your random value. 
    if randy == 1 then --use that variable to check against a number.
        Map1of4:Clone().Parent = Workspace --You don't put the Parent inside of  the parenthesis.
    elseif randy == 2 then --If you have more than one check, use elesif's, not new if statements.
        Map2of4:Clone().Parent = Workspace
    elseif  randy == 3 then
        Map3of4:Clone().Parent = Workspace
    else 
        Map4of4:Clone().Parent = Workspace
    end
end)
0
Please include explanations of what you do rather than just posting code. User#2 0 — 10y
Ad
Log in to vote
0
Answered by
Teeter11 281 Moderation Voter
10 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

My way :

game.Players.PlayerAdded:connect(function() -- fires on player entry
    maps = game.ServerStorage.Maps:GetChildren() --create a model named maps
    randmap = mat.random(1,#maps) -- put all maps in that model
    clonedmap = randmap:Clone()
    clonedmap.Parent = game.Workspace
end)

Your way fixed ENJOY :

Map1of4 = game.ServerStorage.Map1
Map2of4 = game.ServerStorage.Map2
Map3of4 = game.ServerStorage.Map3
Map4of4 = game.ServerStorage.Map4

math.randomseed(tick()) -- makes numbers even more random!!! 

game.Players.PlayerAdded:connect(function()
    local rand = math.random(1,4) -- picks random number and makes it a variable
    if rand == 1 then -- checks random number
        Map1of4:Clone().Parent =game.Workspace
    elseif rand == 2 then-- checks random number
        Map2of4:Clone().Parent = game.Workspace
    elseif  rand == 3 then-- checks random number
        Map3of4:Clone().Parent = game.Workspace
    elseif rand == 4 then-- checks random number
        Map4of4:Clone().Parent = game.Workspace
    end
end)

Answer this question