#How to Bring to the leaderstats a number contained in a textlabel
1 messages · Page 1 of 1 (latest)
For example if the leaderstats is 0 and the textlabel displays 6, i want this to go in leaderstats. In this way the leaderstats will display 6. Same if I have again "10" in the label and it goes in the leaderstats displaying 16 (because 6+10) (of course the number will be added to the leaderstats IF a player touch a part)
Do you still need help I can help you!
Yes i need help
Did u understand what i want to do?
Are you trying to make it so when the text changes it automattially changes the leaderstats ?
Nono, the number will be added to the leaderstat if I click a button/touch a part
How
The value property
Increase with what
Wait
That's true, im going to try
Ok the system works but there is another problem now. When i click the sell button, the number in textlabel goes into leaderstats but if i press again the part that makes the textlabel increase, the textlabel number will start by the last number before pressing the sell button. I want it to start from 0 again @humble venture
I didn't understand what you exactly mean
So
Do you want when it reaches 10 it goes to 0 again
For example if the textlabel is 10 and i press "sell", the leaderstats will increase by 10 and the textlabel will be again 0, but if I press again a part that add 1 everytime to the textlabel, this will start from 11
Did u get it?
Yes
** You are now Level 3! **
Alright so
How can i fix it
So You have for example
- Gold : When you have 10+ Money you can press a button to get 1 gold
- Money : You press a button to gain points here
Is that what you meant?
It's hard to explain
** You are now Level 6! **
Wait
Step 1. Clicking a part will make textlabel increase by 1 everytime
Step 2. If you press a textbutton, the value of textlabel will be added to leaderstats
Step 3. If i press again the part that makes textlabel increase by 1 every click, idk why the textlabel doesnt start from 0 but from the last number the textlabel reached before i pressed the textbutton
For example i added 7 and by clicking again the part that increase textlabel, it will make the textlabel increase by 8
Oh
Okay I understood
@naive vault
The problem is that you are not reseting the textlabel value when you press the textbutton
The problem is that i set textlabel to 0 but when it start increasing, it start from 8 (considering the last example)
Show me the script
Kinda
I closed studio now
You are probabbly using a variable and not reseting it
local player = game.Players.LocalPlayer
local leaderstats = player:FindFirstChild("leaderstats")
local money = leaderstats and leaderstats:FindFirstChild("Monete")
local button = script.Parent
local function onButtonClick()
local playerGui = player:FindFirstChildOfClass("PlayerGui")
local screenGui = playerGui and playerGui:FindFirstChild("ScreenGui")
local textLabel = screenGui and screenGui:FindFirstChild("TextLabel")
if textLabel then
print("TextLabel found, current value:", textLabel.Text)
local number = tonumber(textLabel.Text) or 0
if money and number >= 0 then
money.Value = money.Value + number
print("✅ Coins updated to:", money.Value)
textLabel.Text = "0"
else
warn("⚠️ Error: Invalid number!")
end
else
warn("⚠️ TextLabel not found!")
end
end
button.MouseButton1Click:Connect(onButtonClick)