Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to delete all specifically named models?

Asked by 3 years ago

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.

0
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'. Mystical_Un1verse 9 — 3y
0
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. RegionalNatalie 5 — 3y
0
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. MarkedTomato 810 — 3y
0
^ 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. SummerEquinox 643 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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

  • Hamoodiyt#4822 Talk me there and I'll be happy to help :D
Ad

Answer this question