I have two scripts:
function onTouched(Hit)
if Hit.Parent.Humanoid ~= nil then
name = Hit.Parent.Name
print("Name found")
gui = script.Parent.AccessBlocked:Clone()
par = game.Players:FindFirstChild(name)
gui.Parent = par.PlayerGui
print("gui parent changed")
end
end
script.Parent.Touched:connect(onTouched)
function onTouched(Hit)
if Hit.Parent.Humanoid ~= nil then
name = Hit.Parent.Name
par = game.Players:FindFirstChild(name)
if par.PlayerGui:FindFirstChild("AccessBlocked") then
thescript = par.PlayerGui:FindFirstChild("AccessBlocked")
wait(.5)
thescript:Destroy()
end
end
end
script.Parent.Touched:connect(onTouched)
The scripts have the same parent: a part in workspace
The part has 3 children: the two scripts and a gui named AccessBlocked
I'm trying to make an invisible wall that when I touch, it shows a gui on my screen saying "Out of Bounds". It works except for the deleting part! This is the weird part: It sometimes does delete the gui but only if the wait() isn't present. It isn't deleting it at all.

1 comment
Sometimes :Destroy() does not work. (I don't know why I just haven't looked into it) but try replacing :Destroy with :Remove() it does the same task!