So Basically, I’m making an ore cframe will be equal to another part cframe, the problem is It just ignores the “CFrame” and it just errors.
NOTE I’m using math.random(), IT SHOULDN’T GET THE ORDER IT SHOULD GET THE CFRAME.
Error
11 is not a valid member of Folder "Workspace.Map.SpawnPart.Lv5
Code
GoldOreClone.CFrame = Map.SpawnPart:FindFirstChild(GoldOreClone.Parent:FindFirstChild("LevelName").Value)[math.random(1, #Map.SpawnPart:FindFirstChild(GoldOreClone.Parent:FindFirstChild("LevelName").Value):GetChildren())].CFrame
Any help ASAP is appreciated.
Katrist
(Katrist)
August 3, 2022, 2:37pm
#3
Try this:
local Level = Map.SpawnPart:FindFirstChild(GoldOreClone.Parent:FindFirstChild("LevelName").Value)
GoldOreClone.CFrame = Level:GetChildren()[math.random(1, #Level:GetChildren())].CFrame
(also you should use more variables later on in your coding so it’s more readable)
1 Like
local map = Map
local oreParent = GoldOreClone.Parent
local spawnPartValue = Map.SpawnPart:FindFirstChild(oreParent:FindFirstChild("LevelName").Value)
-- just guessing that spawnPartValue is a folder instance
local randomChild : Instance = spawnPartValue[math.random(1, #spawnPartValue:GetChildren()]
local nextcf = randomChild.CFrame
GoldOreClone.CFrame = nextcf
1 Like
Katrist
(Katrist)
August 3, 2022, 2:39pm
#6
No problem, if you have any more questions, feel free to ask.
Your old code didn’t work because you were trying to get a child called “11”, instead of getting the 11th child.
1 Like