So I have a function thats called errorText(text). It basically changes a gui’s text to the parameter “text”, and then slowly fades out ( slowly changing transparency to 1 ). Here is the script:
function errorText(text)
local textLabel = player.PlayerGui.ErrorMessages.TextLabel
textLabel.Visible = false
textLabel.Visible = true
textLabel.Text = text
task.wait(0.8)
for loop = 0, 1, 0.25 do
textLabel.TextTransparency = loop
task.wait(0.15)
end
textLabel.Visible = false
end
This does work, it does fade out after 0.8 seconds. However, if the player calls this function twice in a row, it breaks. The textlabel fades out at first, after the player called the function again, the first time the player called errorText overlaps with second time calling errorText, glitching it. My question is:
Is there any way to check if the textlabel is visible, if it is, it pauses the last time calling the function errorText() and starts a new one? Thanks.
local debounce = false
function errorText(text)
if not debounce then
debounce = true
local textLabel = player.PlayerGui.ErrorMessages.TextLabel
textLabel.Visible = false
textLabel.Visible = true
textLabel.Text = text
task.wait(0.8)
for loop = 0, 1, 0.25 do
textLabel.TextTransparency = loop
task.wait(0.15)
end
textLabel.Visible = false
end
end
This only prevents other errorText functions being called, but I want it to be like when a new errorText is called, it cancels the last errorText immediately and does the new one ( kind of like overlap the old one )
function errorText(text)
local textLabel = player.PlayerGui.ErrorMessages.TextLabel
textLabel.TextTransparency = 0
textLabel.Visible = true
textLabel.Text = text
task.wait(0.8)
for loop = 0, 1, 0.25 do
if textLabel.TextTransparency < loop then return end
textLabel.TextTransparency = loop
task.wait(0.15)
end
textLabel.Visible = false
end
What I said is incorrect. He wants to be able to click it again, but just overide the last one. So if transparency is going down and is at 0.5. I think he wants it to go back to 0, and overide the old function.
The break won’t work as it isn’t inside a loop. It is inside a function. You also spelt BoolValue incorrectly, so if @2kvigilanxe names the value in workspace BoolValue, it won’t work since it says BoolVlaue in the script.
I’ve been trying to fix this for a while now, but everything I do just makes it disappear instantly and does not even fix the issue. I think this might be possible, but is very difficult. Just leave it as how it is for now, and try again in a week.
There are a lot of different ways to do this, but since @SilentFish20 suggested using .Changed I would actually just suggest encapsulating the entire function. I haven’t checked but I’m fairly sure this will reset the function every time it’s called. You would then just have to change the bool when the player calls it. If I’m wrong then since .Changed is an event you can also use :Disconnect() and then reconnect it when desired.