What am i doing wrong here?

script:

if plr.game.ServerStorage:FindFirstChild("shovel") then
	
	script.Parent.Triggered:Connect(function()
		local part = script.Parent.Parent
		local transparencyStep = 0.05  
		local fadeDelay = 0.05 

		
		local function fadeOut()
			local transparency = part.Transparency
			transparency = transparency + transparencyStep
			part.Transparency = transparency

			if transparency >= 1 then
				part:Destroy()  
				return
			end

			wait(fadeDelay)
			fadeOut()  
		end

		fadeOut()  
		
		script.Parent.Parent.CanCollide = false
		
	end)
end

Please elaborate on what your code is suppose to do and what the problem is

1 Like

I think you should use game.TweenService for this instead of recursion.

local tween = game.TweenService:Create(part, TweenInfo.new(1, Enum.EasingStyle.Linear), {Transparecy = 1});
tween:Play(); tween.Completed:Wait();
part:Destroy();

The part is already destroyed you cannot edit the instance again. (It doesn’t exist)