cozfl
(Luke)
January 20, 2024, 2:37pm
#1
I’m trying to make a click per second ui but it breaks the money display in the UI and keeps it at 0
the error my friend got:
This is the bit of code that I think is doing it:
local amountOfClicks = amount - PreviousClicksAmount
PreviousClicksAmount = amount
if amountOfClicks <= 0 then return end
monPerSec += amountOfClicks
monPerSec.Text = CLICKS_PER_SECOND_STRING_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(ClicksDuringSecond))
monPerSec.Visible = true
task.delay(1, function()
monPerSec -= amountOfClicks
monPerSec.Text = CLICKS_PER_SECOND_STRING_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(ClicksDuringSecond))
monPerSec.Visible = ClicksDuringSecond > 0
end)
end
I can provide the full script if needed.
savio14562
(savio14563)
January 20, 2024, 2:40pm
#2
Try updating
monPerSec += amountOfClicks
monPerSec -= amountOfClicks
to
monPerSec.Text += amountOfClicks
monPerSec.Text -= amountOfClicks
Right now, as the error says, you are adding to the textlabel itself. Not the text.
You might also have to change the line after since it sets it rather than adds on to it.
cozfl
(Luke)
January 20, 2024, 2:47pm
#3
This is the new script:
local function UpdateClicksPerSecond(amount: number)
local amountOfClicks = amount - PreviousClicksAmount
PreviousClicksAmount = amount
if amountOfClicks <= 0 then return end
monPerSec.Text += amountOfClicks
monPerSec.Text = CLICKS_PER_SECOND_STRING_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(ClicksDuringSecond))
monPerSec.Visible = true
task.delay(1, function()
monPerSec.Text -= amountOfClicks
monPerSec.Text = CLICKS_PER_SECOND_STRING_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(ClicksDuringSecond))
monPerSec.Visible = ClicksDuringSecond > 0
end)
end
He’s getting this error now
It could just be me writing it wrong
any corrections would be heavily appreciated!
D4_rrk
(D4rk)
January 20, 2024, 2:49pm
#4
Can you provide the exact line where this error is found?
I’m assuming that you are using NumberValue objects or IntegerValue objects, in which case to change those values you need to do
value.Value -= value2.Value
Also you cannot use arthimitic on text, which is like + and minus, so it’d be something like this
monPerSec.Text = tostring(tonumber(monPerSec.Text) - amountOfClicks))
cozfl
(Luke)
January 20, 2024, 2:54pm
#6
monPerSec.Text += amountOfClicks
The problem is the code is adding a number to the Text property of monPerSec object which is a string. Try this instead:
monPerSec.Text = tostring(tonumber(monPerSec.Text) + amountOfClicks)
...
task.delay(1, function()
monPerSec.Text = tostring(tonumber(monPerSec.Text) - amountOfClicks)
...
end)
cozfl
(Luke)
January 20, 2024, 3:07pm
#8
where would this be put in the script?
i cant figure out where to place it in here
local function UpdateClicksPerSecond(amount: number)
local amountOfClicks = amount - PreviousClicksAmount
PreviousClicksAmount = amount
if amountOfClicks <= 0 then return end
monPerSec.Text += amountOfClicks
monPerSec.Text = CLICKS_PER_SECOND_STRING_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(ClicksDuringSecond))
monPerSec.Visible = true
task.delay(1, function()
monPerSec.Text -= amountOfClicks
monPerSec.Text = CLICKS_PER_SECOND_STRING_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(ClicksDuringSecond))
monPerSec.Visible = ClicksDuringSecond > 0
end)
end
Where you’re adding and minusing the AmountOfClicks from the text.
local function UpdateClicksPerSecond(amount: number)
local amountOfClicks = amount - PreviousClicksAmount
PreviousClicksAmount = amount
if amountOfClicks <= 0 then return end
monPerSec.Text = tostring(tonumber(monPerSec.Text) + amountOfClicks)
monPerSec.Text = CLICKS_PER_SECOND_STRING_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(ClicksDuringSecond))
monPerSec.Visible = true
task.delay(1, function()
monPerSec.Text = tostring(tonumber(monPerSec.Text) - amountOfClicks)
monPerSec.Text = CLICKS_PER_SECOND_STRING_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(ClicksDuringSecond))
monPerSec.Visible = ClicksDuringSecond > 0
end)
end
cozfl
(Luke)
January 20, 2024, 3:14pm
#11
I tried putting that in and im getting this error
Try changing the tonumber(monPerSec.Text)
to (tonumber(monPerSec.Text) or 0)
. Make sure the brackets are included.
1 Like
cozfl
(Luke)
January 20, 2024, 3:25pm
#13
That fixed my issue with the label being broken but the money per second number is stuck at 0
Try this instead:
local monPerSecAmount = 0
local function UpdateClicksPerSecond(amount: number)
local amountOfClicks = amount - PreviousClicksAmount
PreviousClicksAmount = amount
if amountOfClicks <= 0 then return end
monPerSecAmount += amountOfClicks
monPerSec.Text = monPerSecAmount
monPerSec.Text = CLICKS_PER_SECOND_STRING_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(ClicksDuringSecond))
monPerSec.Visible = true
task.delay(1, function()
monPerSecAmount -= amountOfClicks
monPerSec.Text = monPerSecAmount
monPerSec.Text = CLICKS_PER_SECOND_STRING_TEMPLATE:gsub("AMOUNT", FormatNumber.FormatCompact(ClicksDuringSecond))
monPerSec.Visible = ClicksDuringSecond > 0
end)
end
cozfl
(Luke)
January 20, 2024, 3:44pm
#15
I have the same issue, unless I am just doing it wrong.
Can you tell me what the CLICKS_PER_SECOND_STRING_TEMPLATE value is?
In the mean time, try this:
local monPerSecAmount = 0
local function UpdateClicksPerSecond(amount: number)
local amountOfClicks = amount - PreviousClicksAmount
PreviousClicksAmount = amount
if amountOfClicks <= 0 then return end
monPerSecAmount += amountOfClicks
monPerSec.Text = "(+".. monPerSecAmount.. "/sec)"
monPerSec.Visible = true
task.delay(1, function()
monPerSecAmount -= amountOfClicks
monPerSec.Text = monPerSec.Text = "(+".. monPerSecAmount.. "/sec)"
monPerSec.Visible = ClicksDuringSecond > 0
end)
end
cozfl
(Luke)
January 20, 2024, 3:54pm
#17
this script broke the text label again.
this is what the value is:
local CLICKS_PER_SECOND_STRING_TEMPLATE = "(+AMOUNT/sec)"
Can you also include the value of ClicksDuringSecond and which part of the script changes it’s value?
cozfl
(Luke)
January 20, 2024, 3:58pm
#19
value:
local ClicksDuringSecond = 0
value change:
if currency == "mony" then
UpdateClicksPerSecond(amount)
mony.Text = FormatNumber.FormatCompact(amount)
elseif currency == "shinies" then
shinies.Text = FormatNumber.FormatCompact(amount)
end
end
UpdateCurrency("mony", Remotes.GetData:InvokeServer("mony"))
Remotes.UpdateMony.OnClientEvent:Connect(function(amount)
UpdateCurrency("mony", amount)
end)
No, I meant the part of the code that changes the ClicksDuringSecond 's value. Because I don’t see a part of the code that changes it. That variable is the number that shows up in the ‘(+x/sec)’ text.