Hello all, I am working on a game script, in which the script chooses a random Part
out of the "RoundSpawns" Folder
.
I've used this exact same line of code for years, but all of a sudden it seems to be not working.
player.Character.HumanoidRootPart.CFrame = workspace.RoundSpawns[math.random(#roundTeleportsGC)].Position + Vector3.new(0, 5, 0)
Below is what it shows in the Output
.
6 is not a valid member of Folder
Thanks in advance!
when you do workspace.RoundSpawns[math.random(#roundTeleportsGC)]
, it attempts to look for a child or property in the RoundSpawns folder literally named that number (as a number, not a string)
you probably meant to do roundTeleportsGC[math.random(#roundTeleportsGC)]
instead
Maybe you should consider grabbing the table of parts inside the folder and just indexing. This will allow for less errors and you can name the parts inside the folder whatever you like:
local RoundSpawns = workspace:WaitForChild('RoundSpawns') local list = RoundSpawns:GetChildren() --returns a list of all children in RoundSpawns local randomPart = list[math.random(#list)] --we access the list, randomly indexing from 1 to the list's length Character:MoveTo( randomPart.Position + Vector3.new(0, 5, 0) ) --we apply the random part to the character's position
This is assuming the folder only contains instances that hold a Position
property.
Good luck!