Destroy() boolean error

  1. I am currently making a conveyor belt that constantly clones shirts and when it passes 10 seconds I want it to slowly tween transparent and then be Destroyed

  2. The issue is that it tells me:

ServerScriptService.Script:8: attempt to index boolean with 'Destroy' 
  1. Here is my script:
local Workspace = game:GetService("Workspace")
local TweenService = game:GetService("TweenService")

workspace.DescendantAdded:Connect(function(added)
	local shirt = added.Name == "ShirtObject" and added.Parent == Workspace
	if shirt then
		wait(3)
		shirt:Destroy()	
	end
end)

I have it as DescendantAdded because I want it to update for each cloned shirt

I also intend to add a Tween where it slowly fades transparent until it gets destroyed, but I am currently trying to figure out why it won’t Destroy()

1 Like

I think this is because you used ==. == is checking if a is equal to b, therefore its outputting a boolean. The error says that its trying to delete a boolean. = is used to set values of things.

yeah like Boris said

local shirt = added.Name == "ShirtObject" and added.Parent == Workspace

this line outputs true or false so shirt is a bool and you canot destroy boolean
you can make it like that

local Workspace = game:GetService("Workspace")
local TweenService = game:GetService("TweenService")

workspace.DescendantAdded:Connect(function(added)
	if added.Name == "ShirtObject" and added.Parent == workspace and added then then
		task.wait(3)
		added:Destroy()	
        end

end)

and wait is deprecated

The condition checks whether added.Name is ShirtObject and whether added.Parent is Workspace, but this results in shirt being a boolean rather than the object.

Easy fix:

local Workspace = game:GetService("Workspace")
local TweenService = game:GetService("TweenService")

workspace.DescendantAdded:Connect(function(added)
	if added.Name == "ShirtObject" and added.Parent == Workspace then task.wait(10)
		local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
		local tween = TweenService:Create(added, tweenInfo, {Transparency = 1})
		tween:Play()
		tween.Completed:Connect(function()
			added:Destroy()
		end)
	end
end)