Tool deleting in player backpack

Give this a go

local replicatedStorage = game:GetService("ReplicatedStorage")

local gun = replicatedStorage:WaitForChild("MK-18")
local gunSpawn = workspace.Spawners:WaitForChild("Spawn")

local spawned = false

while wait(5) do
	if spawned then
		spawned = false
		
		if gunSpawn:FindFirstChild(gun.Name) then
			gunSpawn[gun.Name]:Destroy()
		end
	else
		spawned = true
		
		local gunClone = gun:Clone()
		gunClone.Parent = gunSpawn
	end
end

Your gun would get deleted instantly

its fixed now, i got a question on how you can use

while true do

Nvm, I couldn’t read. But there is no point of adding 2 waits and checking if gun is a gun spawn.

while true do loop will always run cuz the “true” will be always “true”
for example you can do smth else by :

local Test = true
while Test do -- while Test is true

end
1 Like

while true do is a infinite loop. Anything in that loop would run indefinitely unless there is a yield.

1 Like

Also the if statement checking if the gun is the spawner is completely useless and you can simply use :Destroy instead of using debris service.

Alright, well thank you all so much for you help guys, i really apperciate it!

1 Like

no, debris is a better alternative way than :Destroy()

Not in this situation. You’re not using debris to delete something after x amount of seconds so delete would be more useful.

that if statement isn’t useless, cuz if we remove that statement the gun will get removed from the player’s character/backpack or anywhere else.

You should use :Destroy this situation and debris service when you have to deal something like

coroutine.wrap(function()
	wait(5)
	instance:Destroy()
end)()

Why are you also cloning the gunSpawn tho?

I fixed that issue, dont worry lol

there is no such a thing called Delete, and up there you said :Destroy not :Delete()
also up there you mentioned :Destroy() Not :Delete()

Sorry im making typos but you get my point

Cloning the Spawner from ReplicatedStorage.

GunSpawn is in workspace not replicated storage

oh ye, just realised that lol, removed the clone.

Lol, so the clone isnt necessary.