I'm currently attempting to make a script to delete all vehicles that are named 'Empty Car'
This is my current script;
game:GetService("Players").PlayerAdded:Connect(function(player) player.Chatted:Connect(function(message) if message:lower() == tostring("?dv all"):lower() then for v in pairs (game.workspace:GetChildren())do if v.Name == 'Empty Car' then v:Destroy() end end end end) end)
I'm getting an error for "Workspace.Delete All Vehicles Script.Scripts.ServerScript:5: attempt to index number with 'Name'
That directs me to the if v.Name == 'Empty Car' then line.
Would anyone know why this is happening?
Also would appreciate if anyone has an easier solution or a better written code.

4 comments
Not a pro at scripting here, but I think it may be easier inserting a self delete script in all of the models with the name 'Empty Car'.
Yeah I was planning on adding that, but the thing is not everybody likes to delete their car, they don't even ask a staff member to delete their car, if I can't find a solution I'll most likely just do that.
The problem is the for loop; for i, v in ipairs(workspace:GetChildren()) do; ipairs() is used for arrays and pairs() is used for dictionaries.
^ Yes and no. The actual problem is that the only provided variable will assign to index in the loop. You are fundamentally correct about ipairs and pairs, but which one gets used here will not break the code.