I’m trying to make a car spawner for my friends game, It throws this error: Invalid argument #1 to pairs (table expected got instance)
, though I used :GetChildren()
to get a table.
Code
local replicatedStorage = game:GetService("ReplicatedStorage")
local remotes = replicatedStorage:WaitForChild("remotes")
local spawnCar = remotes:WaitForChild("spawnCar")
local cars = replicatedStorage:WaitForChild("Cars")
for i,v in pairs(cars:GetChildren()) do
local button = Instance.new("TextButton",script.Parent)
button.Name = v.Name
button.Text = v.Name
button.TextSize = 18
button.TextWrapped = true
button.BorderSizePixel = 0
button.BackgroundColor = Color3.fromRGB(33,33,33)
button.MouseButton1Click:Connect(function()
spawnCar:FireServer(v.Name)
end)
end