Confused on how I can Destroy Tool after certain seconds

Hello there! So what my script does is that it basically gives every player a tool, but what I want to do is Destroy it from every players inventory when x seconds is up. I’ve tried Destroy() and making it wait(8) but if I do that, it seems to give the tools to all players every 8 seconds and then deleting from their inventory with all the remaining players in-game.

Code:


local plrs = {}

for i, player in pairs(game.Players:GetPlayers()) do
	if player then
	table.insert(plrs,player)
	end
end
---
for i, player in pairs(plrs) do
	if player then
		character = player.Character
        if character then

		local BlowDryer = game.ServerStorage.Maps.ToolMap.BlowDryer:Clone()
		BlowDryer.Parent = player.Backpack
		end
   end
end

Help is appreciated! :slight_smile:

1 Like

Use game.Debris:AddItem() :wink: This function can be used to add an item, then destroy it without having the script to yield (Or wait) any sort of its code

It’s kinda like a spawn/coroutine I suppose

local plrs = {}

for i, player in pairs(game.Players:GetPlayers()) do
	if player then
	table.insert(plrs,player)
	end
end
---
for i, player in pairs(plrs) do
	if player then
		character = player.Character
        if character then

		    local BlowDryer = game.ServerStorage.Maps.ToolMap.BlowDryer:Clone()
		    BlowDryer.Parent = player.Backpack
            game.Debris:AddItem(Blowdryer, 8)
		end
   end
end
2 Likes

Man cannot thank you enough every time I need help with scripting! :joy:
Tysm! :pray: :grinning_face_with_smiling_eyes:

1 Like