I have a system where if an item(default roblox tool) is not picked up after it's despawn time, it destroys itself and is despawned, however if it is picked up by a player, it is counted as "PickedUp" and will no longer despawn. Since this is my first time doing something like this, I was wondering if there is a more effecient way to write this code.
--spawning stuff(just an example)
local ToolClone = Tool:Clone()
ToolClone.Parent = game.Workspace
spawn(function()
local PickedUp = false
ToolClone.AncestryChanged:Connect(function(child, parent)
if parent:FindFirstChild("Humanoid") or ToolClone:IsDescendantOf(game.Players) then
PickedUp = true
end
end)
wait(300)
if ToolClone then
if PickedUp = false then
ToolClone:Destroy()
end
end
end)

1 comment
This is good, thank you.