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

How would i fix my map randomiser with a number error?

Asked by 4 years ago
Edited 4 years ago

I have been trying to make a map randomiser for the past 2 hours and i am having trouble it says "attempt to index number with 'Map'" on line 3 i have tried math.random(1, #Maps), random.new(1, #Maps) and neither have worked please help as i cant continue making a game without this working.

EDIT: I changed the code a little still dosent work NEW ERROR: ServerScriptService.MapChooser.Selector:14: attempt to index number with 'Sky'

local Maps = game.ServerStorage:WaitForChild("Maps"):GetChildren()
local Map = math.random(1, #Maps)
local MapClone = Maps[Map]:Clone()
local Intermission = game.ReplicatedStorage:WaitForChild("MapStuff"):WaitForChild("Intermission")

while wait() do
    print("Intermission.")
    if Intermission.Value == true then
        wait()
    elseif Intermission.Value == false then
        print("No Longer Intermission.")
        MapClone.Map.Parent = workspace
        print("Cloned To Workspace.")
        Map.Sky.Parent = game.Lighting
        print("Lighting.")
    end
end
0
Try doing Map[Sky].Parent DrShockz 233 — 4y
0
When you are using :GetChildren() you are creating an array. So now to find a random map in that array, you need to generate a random number key(using math.random()) then you need to reference the array as you usually would. Maps[math.random(1,#Maps)] ForeverBrown 356 — 4y
1
ForeverBrown i already fixed it thanks to HappyJakeyBoy EnzoTDZ_YT 275 — 4y
1
Just giving a brief description of what is actually happening. ForeverBrown 356 — 4y
1
Oh thanks EnzoTDZ_YT 275 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

Try this

local Maps = game.ServerStorage:WaitForChild("Maps"):GetChildren()
local Map = math.random(1, #Maps)
local MapClone = Maps[Map]:Clone()
local Intermission = game.ReplicatedStorage:WaitForChild("MapStuff"):WaitForChild("Intermission")

while wait() do
    print("Intermission.")
    if Intermission.Value == true then
        wait()
    elseif Intermission.Value == false then
        print("No Longer Intermission.")
        MapClone.Map.Parent = workspace
        print("Cloned To Workspace.")
        MapClone.Sky.Parent = game.Lighting
        print("Lighting.")
    end
end
0
Thanks Also Your Welcome :D HappyJakeyBoy 67 — 4y
0
Answer unaccepted. Horrible answer, lacks the information necessary to help the asker. DeceptiveCaster 3761 — 4y
1
Actually BashCaster it worked fine EnzoTDZ_YT 275 — 4y
0
It's a bad answer because it does not explain the code. It is a spoonfeed answer. DeceptiveCaster 3761 — 4y
View all comments (3 more)
1
he explained the code through discord he said he had go shops so he went to explain on discord EnzoTDZ_YT 275 — 4y
1
When i did Map.Sky.Parent it checked the model for Map for sky even though sky is under the folder with same parent as map EnzoTDZ_YT 275 — 4y
0
Nice rep manipulation DeceptiveCaster 3761 — 4y
Ad
Log in to vote
0
Answered by
DrShockz 233 Moderation Voter
4 years ago

I believe you need to add a bracket around it.

map = Maps[math.random(1, #Maps)]

Source

1
still got trouble with sky EnzoTDZ_YT 275 — 4y
1
Odd can you send a screenshot of the errors please :) DrShockz 233 — 4y
1
Can't do screenshots as my screenshot software is updating also my prntscrn button broke but i get the error.. ServerScriptService.MapChooser.Selector:14: attempt to index number with 'Sky' EnzoTDZ_YT 275 — 4y
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

The Map.Sky.Parent = game.Lighting is probably wrong. Maybe you should change it to Map.Sky.Parent = game:GetService("Lighting").

0
If there still errors, comment below, thanks too:) Xapelize 2658 — 4y
1
That's not what the error is about... DeceptiveCaster 3761 — 4y
1
Still got error EnzoTDZ_YT 275 — 4y

Answer this question