Tool deleting in player backpack

I made a tool that spawns every 5 seconds and despawns in another 5 seconds, it works fine but the issue is, whenever you would pick up the item, 5 seconds later it would delete in the players backpack and spawn back at the spawn

local ReplicatedStorage = game.ReplicatedStorage
local Gun = ReplicatedStorage:WaitForChild('MK-18')
local GunSpawn = workspace.Spawners:WaitForChild('Spawn')

while wait(5) do
	local NewGun = GunSpawn:Clone()
	NewGun.Parent = GunSpawn
	game:GetService'Debris':AddItem(NewGun ,5)
end

I tried everything for fixing it, Any advice would be good thanks!

1 Like

you could check for its parent like so

local ReplicatedStorage = game.ReplicatedStorage
local Gun = ReplicatedStorage:WaitForChild('MK-18')
local GunSpawn = workspace.Spawners:WaitForChild('Spawn')

while wait(5) do
	local NewGun = GunSpawn:Clone()
	NewGun.Parent = GunSpawn
    if NewGun.Parent == GunSpawn then
	game:GetService'Debris':AddItem(NewGun ,5)
end
end
1 Like

i tried that, but i didnt put a second = on

if NewGun.Parent == GunSpawn then

ill try it out, thank you so much

1 Like

okay so i tried this out, and the gun isnt spawning at all now, any idea how?

You’re cloning the gun spawner.

yeah i literally just realised LOL

I’ve been trying to see why you were cloning the spawner for 5 minutes now.

yeah, you’re cloning the spawner

Yeah, i kinda rushed to type this script out, so thank you for reminding me

okay, so i pick up the gun and the gun still gets deleted out of the players inventory and hands.

The debris service is deleting the gun you just cloned after 5 seconds.

your code should look like this

local ReplicatedStorage = game.ReplicatedStorage
local Gun = ReplicatedStorage:WaitForChild('MK-18')
local GunSpawn = workspace.Spawners:WaitForChild('Spawn')
local GunSpawnClone = GunSpawn:Clone()
GunSpawnClone.Parent = workspace
while true do
        task.wait(5)
	local NewGun = Gun:Clone()
	NewGun.Parent = GunSpawnClone
    if NewGun.Parent == GunSpawnClone then
	game:GetService'Debris':AddItem(NewGun ,5)
end
end

So, you want the mk18 appear for 5 seconds and despawns after another 5 from the gun spawner?

Now the gun is spawning infinetly lol, im so sorry for wasting your guys time ;-;

no worries, i updated the code try again.

Can you send me a download of the model?

yeah, basically you wait for the gun to spawn, then it spawns, if you dont pick it up in like 5 seconds the gun gets removed and spawns another one

of the tool model? its fe gun kit

its STILL deleting from the players backpack if you pick it up
I think its this line thats basically making it delete in the players backpack

game:GetService'Debris':AddItem(NewGun ,5)

yup, because its waiting 5 seconds while the player has the tool. you could do this :

local ReplicatedStorage = game.ReplicatedStorage
local Gun = ReplicatedStorage:WaitForChild('MK-18')
local GunSpawn = workspace.Spawners:WaitForChild('Spawn')
while true do
    task.wait(5)
	local NewGun = Gun:Clone()
	NewGun.Parent = GunSpawn
    task.wait(5)
    if NewGun.Parent == GunSpawn then
	game:GetService'Debris':AddItem(NewGun ,0)
end
end