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

why is this script giving 0?

player = script.Parent.Parent.Parent.Parent.Parent
bal = player.bal
text = script.Parent.Text
num = tonumber(text) 

script.Parent.FocusLost:connect(function()
	print(player.Name)
	print(text)
  print(num)
	if player.leaderstats.Cash.Value >= num then
		print(text)
		bal.Value = bal.Value + num
	end
end)

I'm trying to make an ATM, this is for the deposit part. no matter what i put into the textbox, it always prints this:

Player1

0

0

0

and it doesn't add to the bal value. whats worng with this?

1 answer

✓ Accepted answer

You're storing a copy of the .Text of script.Parent(A TextBox, presumably) into the variable text. What you should do is store the TextBox itself, so you can get its .Text later on.

player = script.Parent.Parent.Parent.Parent.Parent
bal = player.bal
text = script.Parent

script.Parent.FocusLost:connect(function()
    print(player.Name)
    print(text.Text)
  print(tonumber(text.Text))
    if player.leaderstats.Cash.Value >= tonumber(text.Text) then
        print(text.Text)
        bal.Value = bal.Value + tonumber(text.Text)
    end
end)

1 comment

0

thank you

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