Hello! So, basically I want that so when a new player joins in the server, it choose a random grid and clone it for the player, so I made this code:
Players.PlayerAdded:Connect(function(player)
local Plot = Instance.new("Folder", workspace.BuildingAreas)
Plot.Name = player.Name
wait(.1)
for _,grids in pairs(ReplicatedStorage:WaitForChild("Building").Stored:GetChildren()) do
local chosenGrid = grids[math.random(1, #grids)]
local playerGrid = chosenGrid:Clone()
playerGrid:WaitForChild("Avaliable").Value = false
playerGrid.Parent = workspace:WaitForChild("BuildingAreas"):FindFirstChild(player.Name)
end```
But when I go test it, I get this error: "attempt to get length of a Instance value"
How I can solve this? Any help is appreciated.
Players.PlayerAdded:Connect(function(player)
local Plot = Instance.new("Folder", workspace.BuildingAreas)
Plot.Name = player.Name
wait(.1)
for _,grids in pairs(ReplicatedStorage:WaitForChild("Building").Stored:GetChildren()) do
local chosenGrid = grids:GetChildren()[math.random(1, #grids:GetChildren())]
local playerGrid = chosenGrid:Clone()
playerGrid:WaitForChild("Avaliable").Value = false
playerGrid.Parent = workspace:WaitForChild("BuildingAreas"):FindFirstChild(player.Name)
end