This script is supposed to make a GUI fade in when touched, and once the BackgroundTransparency property of the Frame is 0 or below, it should delete itself after 1 second using these lines of code:
if frame.BackgroundTransparency <= 0 then
wait(1)
script:Destroy()
end
The script will not delete itself though, does anyone know how I can fix this?
If it helps, here is the script that is supposed to make the Frame fade in, and be destroyed:
door = script.Parent
door.Touched:connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local char = humanoid.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local guis = plr.PlayerGui
local frame = guis.Load.Frame
wait(0.5)
while frame.BackgroundTransparency > 0 do
wait(0.01)
frame.BackgroundTransparency = frame.BackgroundTransparency - 0.1
end
end)
Setting script.Disabled to true wont work either. You can try using a variable, setting it to false when you want the script to stop running and check it before you do anything (also disconnect all functions before setting it to false)