How do I have the TextLabels text display only once in a changed event?

I am trying to make script where when a number value get’s to a certain value, it displays the message and does it once. But instead it does this:
robloxapp-20220626-2210440.wmv (692.9 KB)

Script Code:

ModuleScript code:
Screenshot 2022-06-26 215248
I have no idea how to only display the text once. Is there even a way here?

It seems that the changed function is being called repetitively which then keeps rewriting the message. I would try adding a debounce in your module script

Yea but I want the text to only display once and stays that way until it reaches a higher or lower value. Is a debounce the only way?

Here’s what I’d do, I’ll clean it up.

local texts = {
    [3500] = "Value 3500 text here",
    [3000] = "Value 3000 text here",
    [1500] = "Value 1500 text here",
    [500] =  "Value 500 text here",
}
Temp.Changed:Connect(function(value)
    if value >= 3500 then
        if Status.Text == texts[3500] then continue end
        typwrite(Status, texts[3500], 0.05)
    elseif value >= 3500 then
        if Status.Text == texts[3000] then continue end
        typwrite(Status, texts[3000], 0.05)
    elseif value >= 1500 then
        if Status.Text == texts[1500] then continue end
        typwrite(Status, texts[1500], 0.05)
    value >= 500 then
        if Status.Text == texts[500] then continue end
        typwrite(Status, texts[500], 0.05)
    end
end)

robloxapp-20220626-2210440.wmv (692.9 KB)

Script code:

Unless I am positioning the script wrong it does the same thing pretty much.

I figured, it won’t if you let the anim play out, that’s what I fixed. To fix the rest of your error:

local debounce = false
local cooldownTime = 0
local texts = {
    [3500] = "Value 3500 text here",
    [3000] = "Value 3000 text here",
    [1500] = "Value 1500 text here",
    [500] =  "Value 500 text here",
}
Temp.Changed:Connect(function(value)
    if debounce then 
        wait(cooldownTime)
    end
    if value >= 3500 then
        if Status.Text == texts[3500] then continue end
        typwrite(Status, texts[3500], 0.05)
        cooldownTime = tonumber(texts[3500]:len())*0.05
    elseif value >= 3500 then
        if Status.Text == texts[3000] then continue end
        typwrite(Status, texts[3000], 0.05)
        cooldownTime = tonumber(texts[3000]:len())*0.05
    elseif value >= 1500 then
        if Status.Text == texts[1500] then continue end
        typwrite(Status, texts[1500], 0.05)
        cooldownTime = tonumber(texts[1500]:len())*0.05
    value >= 500 then
        if Status.Text == texts[500] then continue end
        typwrite(Status, texts[500], 0.05)
        cooldownTime = tonumber(texts[500]:len())*0.05
    end
end)

Still untested

robloxapp-20220627-1152527.wmv (560.1 KB)

One thing I did realize though is that in the code it gave me a warning that it couldn’t be converted to a number.
Screenshot 2022-06-27 115231

Script code:

No errors either so yea.

1 Like

What if you change that to:

tonumber(#texts[3500])

Change for all of error/warning goes away

BTW can you make it so we don’t have to download the video. (Anything under 1m shouldn’t have to be downloaded)

  • Warning text remains
  • No errors
  • And does the same thing in the last footage

script code:

It’s really important I get a solution to this problem because otherwise I am gonna have to cancel this project altogether.

Wait, you forgot to add the #
Sorry, I’m not that helpful I’m on mobile

Where do I put the hashtag in my code though?

You forgot the # before texts

Also at that point you don’t need tonumber so it can just be:
#texts[3500]
And ofc change 3500 for all

BTW I didn’t see any of the videos cause I’m on mobile and don’t want to download them:

The same like I mentioned above.

script code:

Did you try it like that?
Also, like I said before:

Yea I did add them.

Here is a zoomed in screenshot of that exact screenshot.

About that I don’t know how so.

No, I see that you have it in the tonumber, I mean remove the to number, so it should only be:

Also,

All you have to do is click the upload icon and as long as it’s under 1min it should be allowed

Why not just put a debounce until the typewriter function has completed? I’d give you a code example, but you posted an image of your code instead of actual code. Also you should be using task.wait instead of just wait.

Is this what you meant by that?

Screenshot 2022-06-26 215248

You still need a debounce. Also please post code instead of pictures.

Copy your code and paste it in between ``` like this:
```Lua
print(‘Hello World!’)
```
It will show up as

print('Hello World!')

I am doing this wrong somehow

script:

game.Players.PlayerAdded:Connect(function(Player)
local typewrite = require(game.ReplicatedStorage.typewrite)

local StatusGui = Player.PlayerGui:WaitForChild("StatusGui")
local Status = StatusGui.MainFrame.Status		
local Temp = workspace.Temp
Temp.Changed:Connect(function(Value)	
if Value > 3500 then
typewrite(Status,"WARNING. ACTIVATE THE COOLANT IMMEDIATELY! CORE IS NEAR MELTDOWN!",0.05) 
elseif Value > 3000 then
typewrite(Status,"The core is starting to overheat. You should cool the core down a bit.",0.05) 		
elseif Value > 1500 then
typewrite(Status,"Core is at normal tempatures.",0.05)		
elseif Value > 500 then
typewrite(Status,"The core is getting too cold. You should warm the core up.",0.05) 	
end		
		
end)

end)

Module:

local function typewrite(object,text,WaitingTime)
for i = 1,#text,1 do
object.Text = string.sub(text,1,i)		
task.wait(WaitingTime)		
end	
end

	
	

return typewrite