Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a GUI that adds the input to a players leader stat?

Asked by 6 years ago

What i am asking is how to fix this script because as of now it does nothing. It was intended for a player to type in and the input was supposed to be added to that players leaderstat named "Money" I have no idea how to fix this can someone please teach me!!!

The Local Script:

script.Parent.TextBox.FocusLost:Connect(function()
    local text = script.Parent.TextBox.Text
    local money = game.Players.LocalPlayer:WaitForChild("leaderstats").Money.Value
    money = money + text
 end)

Screen GUI Setup:

https://pasteboard.co/HrhRSRL.png

0
You can't have any letters in your textbox.If you do have any and want to keep them, i'd look into string patterns. http://wiki.roblox.com/index.php?title=String_pattern stepatron 103 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You have to convert the text to a string using to number. You also can't make a variable with the value the way you did at line 3, because it will make money variable a number, not the actual int value. Try this code.

1   script.Parent.TextBox.FocusLost:Connect(function()
2       local text = script.Parent.TextBox.Text
3       local money = game.Players.LocalPlayer:WaitForChild("leaderstats").Money
4       money.Value = money + tonumber(text)
5    end)

Ad

Answer this question