Number is nto a valid memeber of folder when gettign random object

Im trying to get a rando object fro ma folder, and it just returns that its not containing a number in the folder.

heres the code

local ObjFolder = game.ReplicatedStorage:WaitForChild("SpawnTables")

local Spawns = script.Parent

task.wait(5)
for _, SpawnPad in pairs(Spawns:GetChildren()) do
	if SpawnPad.Name == "ItemSpawn" then
		if Class.Value == "Common" then
			randomroom = ObjFolder.Common[math.random(1,#ObjFolder.Common:GetChildren())]
			local ClonedRoom = randomroom:Clone()
			ClonedRoom.Parent = game.Workspace
			ClonedRoom:MoveTo(SpawnPad.Position)
			ClonedRoom:PivotTo(SpawnPad.CFrame)
			
			
		elseif Class.Value == "Rare" then
			randomroom = ObjFolder.Rare[math.random(1,#ObjFolder.Rare:GetChildren())]
			local ClonedRoom = randomroom:Clone()
			ClonedRoom.Parent = game.Workspace
			ClonedRoom:MoveTo(SpawnPad.Position)
			ClonedRoom:PivotTo(SpawnPad.CFrame)
			
			
		elseif Class.Value == "Legendary" then
			randomroom = ObjFolder.Legendary[math.random(1,#ObjFolder.Legendary:GetChildren())]
			local ClonedRoom = randomroom:Clone()
			ClonedRoom.Parent = game.Workspace
			ClonedRoom:MoveTo(SpawnPad.Position)
			ClonedRoom:PivotTo(SpawnPad.CFrame)
			
			
		end
	end
end

When i looked online, all the answers said “put :getchildren()” but i already do that

(Also it says cloned room cus i took it from my other game, witch the script DOES work in, just not in this new game.)

1 Like

I either don’t see it or it’s not there. What’s Class? I don’t see
local Class = ---
anywhere?
Perhaps you meant to put

SpawnPad.Class.Value = ---

?

1 Like

whoa what the hell??? ig it didnt send that? at the top it SHOULD say this

local Class = script.Parent.Class

Wierd, but theres class
(also yes in the actual script it does have that)

1 Like

can you get a picture of the items in the folder?

1 Like

image

1 Like

What I’m confused about is that you say you’re trying to get a random object to spawn, but your script doesn’t seem that way. It’s kind of hard to explain. Can you tell me which line is giving errors?
You could change this:

to

	if SpawnPad == "1" then --- 1, 2, or 3

wait nope ignore that I meant to say the line after that

to

	if SpawnPad.Name == "Common" then --- rare or legendary

I am not sure really.

1 Like

spawn pad is an instance, and the script basically finds the class name (the rarity of the spawns) then grabs a random item from the folder and spawns (clones) it.

This same script was used in another game i made, and it worked fine. only diffrence is the location of the script.

oh, the spawnpad is an instance, and the class value is a string. so i cant do that

Alright, so, the problem is quite simple, yet easy to miss due to the clusters and jumbles of code that you have.
Basically, the issue is in here:

the brackets [] basically serve the same function as a period ., translating your code would probably make it more understandable, so i’ll assign a random number for you:

randomroom = ObjFolder.Common[math.random(1, 5)]

As you see, what this line of code does is look inside an INSTANCE for a random number instead of an ARRAY or Table…
To fix this, simply do as such:

local room = ObjFolder.Common:GetChildren()
random_number =  math.random(1,#ObjFolder.Common:GetChildren())
local randomroom = room[random_number]

Please do reply if this helps, and do not be ashamed for making such a simple mistake!

You could try

local RandomObject = math.Random(1.3)

if RandomObject == 1 then
--- 
elseif RandomObject == 2 then
---
elseif RandomObject == 3 then
---
end

But this might not go with what you’re doing

try thies

local ObjFolder = game.ReplicatedStorage:WaitForChild("SpawnTables")

local Spawns = script.Parent

task.wait(5)
for _, SpawnPad in pairs(Spawns:GetChildren()) do
	if SpawnPad.Name == "ItemSpawn" then
		if Class.Value == "Common" then
			randomroom = ObjFolder.Common:GetChildren()[math.random(1,#ObjFolder.Common:GetChildren())]
			local ClonedRoom = randomroom:Clone()
			ClonedRoom.Parent = game.Workspace
			ClonedRoom:MoveTo(SpawnPad.Position)
			ClonedRoom:PivotTo(SpawnPad.CFrame)
			
			
		elseif Class.Value == "Rare" then
			randomroom = ObjFolder.Rare:GetChildren()[math.random(1,#ObjFolder.Rare:GetChildren())]
			local ClonedRoom = randomroom:Clone()
			ClonedRoom.Parent = game.Workspace
			ClonedRoom:MoveTo(SpawnPad.Position)
			ClonedRoom:PivotTo(SpawnPad.CFrame)
			
			
		elseif Class.Value == "Legendary" then
			randomroom = ObjFolder.Legendary:GetChildren()[math.random(1,#ObjFolder.Legendary:GetChildren())]
			local ClonedRoom = randomroom:Clone()
			ClonedRoom.Parent = game.Workspace
			ClonedRoom:MoveTo(SpawnPad.Position)
			ClonedRoom:PivotTo(SpawnPad.CFrame)
			
			
		end
	end
end

where do i put this
char limit

Replace:

With:

char limittttttt

this worked, thanks!
char limit

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.