for i,v in pairs(game.Workspace:GetDescendants()) do if v.Name == "Spawnpoint" then local ChosenSpawn = (v[math.random(1, #v)]) game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = ChosenSpawn.CFrame end end
I'm trying to make a script so that it gets the descendants of the workspace to find all bricks named "Spawnpoint", and then making a random pick of one of the spawn bricks, and then teleporting the player to the brick.
Whenever I try to test the script in studio, I keep getting this error: attempt to get length of local 'v' (a userdata value) Any way I can fix this?
You're trying to use a length operator on an object.
local ChosenSpawn = (v[math.random(1, #v)])
I believe what you're wanting is:
local ChosenSpawn = (v[math.random(1, #(v:GetChildren()))])