Hello, I was wondering how I could use :Destroy() twice on a model don’t ask me why I need this its a long story so I was just wondering how I could do it.
You can’t. If you destroyed it already, why do it again?
This is why I need it destroyed twice is because I have this model and it has to be destroyed twice for it to destroy for some weird reason I don’t know why, but thats why.
that’s not the case. you’re doing something wrong.
Wouldn’t you just use an if statement to check that the object is still around for you to destroy?
If not then you needn’t worry about it.
Nevermind, as @WorldPosition said, because it’s still around means you’ve made an error.
If this is happening you dont just repeat the destroy, you figure out what’s causing the issue.
I have for hours and still can’t find the issue.
Ok I will go ahead and try that now.
Have you checked that you’re destroying the right instance?
You have a two models with the same name?
In the output it says attempt to call a nil value so how should I fix that?
This means that the model has already been deleted / does not exist
The weird thing is it still shows up on my screen but the error comes at line 86 (the code is lines 60 - 86)
local module = {}
function module.Clicked(plr,item)
if plr then
if plr.Character and not plr:FindFirstChild("Contestant") then
local position
if item:IsA("Model") then
position = item.PrimaryPart.Position
else
position = item.Position
end
module.DropTools(plr,game.Workspace.map,position)
print("Dropped Keyhandles")
if game.ServerStorage.Tools:FindFirstChild(item.Name) then
local clonedTool = game.ServerStorage.Tools[item.Name]:Clone()
clonedTool.Parent = plr.Backpack
plr.Character.Humanoid:EquipTool(clonedTool)
item:Destroy()
print("Equipped The tool object")
end
end
end
end
return module
You could try this if you want.
repeat
item:Destroy()
until item == nil
@TransportLogistics You’re really suggesting trying to delete item in a repeat loop? There’s a bigger problem. I have never once needed to delete something “twice” or create a loop to delete it, and I’ve never heard of anyone else doing it either.
I’m very far from confident it will work, but it is important to try any possible solutions.
Not if the possible solution leads to hacky, messy code. You should never delete something with a loop, it really doesn’t make sense. He should be trying to solve the bigger problem here. He hasn’t provided enough information to us.
If you use Destroy() and your model is still there the reasons may be so many. Here are some:
- You have two models with the same name
- You are trying to destroy something that doesn’t exist
- You mispelled it’s name
- You are not getting it by the right way. For example you are trying to get it with script.Parent ecc… , but you’re writing the wrong path
- The model got yet destroyed
Can you provide us with the entire script?
My guess is that the “item” he is passing through to the function, sometimes doesn’t end up getting passed through.