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)
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
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)
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)
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.
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