#How to Bring to the leaderstats a number contained in a textlabel

1 messages · Page 1 of 1 (latest)

naive vault
#

Guys I need help. How to bring to leaderstats a number contained in a textlabel? This thing must be activated if a player touch a part. Pls help

#

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)

humble venture
naive vault
#

Did u understand what i want to do?

humble venture
naive vault
#

Nono, the number will be added to the leaderstat if I click a button/touch a part

humble venture
#

Okay

#

just increase the value of the leaderstats

naive vault
#

How

humble venture
#

The value property

naive vault
#

Increase with what

humble venture
#

number

#

myNumberValue.Value += 50

#

Did you get it ? @naive vault

naive vault
#

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

humble venture
#

I didn't understand what you exactly mean

#

So

#

Do you want when it reaches 10 it goes to 0 again

naive vault
#

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?

humble venture
#

Yes

whole crownBOT
#

studio** You are now Level 3! **studio

humble venture
#

Alright so

naive vault
#

How can i fix it

humble venture
#

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?

naive vault
#

It's hard to explain

whole crownBOT
#

studio** You are now Level 6! **studio

naive vault
#

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

humble venture
#

Oh

#

Okay I understood

#

@naive vault

#

The problem is that you are not reseting the textlabel value when you press the textbutton

naive vault
#

The problem is that i set textlabel to 0 but when it start increasing, it start from 8 (considering the last example)

humble venture
#

Show me the script

humble venture
naive vault
#

If u want i can show u tomorrow

#

Btw ty for the help u are giving to me

naive vault
#

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)