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.
Maybe you can use some checks to check if there is any players in the car and if that's false then Change the name of the model to Empty(Owner.Name)
then check if someone said ?dv all
then make it run throw all the empty Cars and till it finds the car that has his name in it
ex : If Owner.Name == Player.Name then.....
Something like that depends on the way of the code.
if true then destroy the car
else Say error in a UI or in a Wisper
wish this helped :D
I am new so Don't judge me XD