hi! I'm a little rusty with scripting since I haven't done it in a while. In a game I'm working on, I have a button that adds a part inside the player called "Character." I also have a button that deletes this part when its not being used. (For context, the player is only supposed to have this brick attached to them in a specific area, and then it's removed once they leave that area.)
This is the script:
debounce = false
function onTouch(hit)
if game.Players:FindFirstChild(hit.Parent.Name) ~= nil and debounce == false then
local player = game.Players:FindFirstChild(hit.Parent.Name)
local c = player.Character:GetChildren()
local character = player.Character:WaitForChild("Character")
debounce = true
character:Destroy()
for name, child in pairs(player.Character:GetDescendants()) do
if child:IsA("Part") or child:IsA("MeshPart") or child:IsA ("UnionOperation") or child:IsA("Decal") then
child.Transparency = 0
end
end
end
end
script.Parent.Touched:connect(onTouch)
I'm guessing the problem comes somewhere in this part of the script:
local character = player.Character:WaitForChild("Character")
debounce = true
character:Destroy()
It works the first time perfectly, but if I touch the first button (which adds the part back into my character) and then back on this button that's supposed to destroy it, it doesn't work the second time around. Does anyone know why that could be? There's no error in the output.

2 comments
oh that's what it was! thank you!
yw