Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

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

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.