TextBox problem please help

so i wanted the script to print the text that are in the text box but instead it printed the default text
–local script —
local player = script.Parent.Parent.TextBox.Text

local amount = tonumber(script.Parent.Parent.Amount.Text)

 script.Parent.MouseButton1Click:Connect(function()

 print(player)

 print(amount)

end)

gns ikdh

when i click give it should print coolguest_6666 and 10000

but instead it print the default text

please help

You are defining the player and the amount before they are pressing the button, so it will be nil, you should update the value when they press the button like this:


 script.Parent.MouseButton1Click:Connect(function()
local player = script.Parent.Parent.TextBox.Text

local amount = tonumber(script.Parent.Parent.Amount.Text)
 print(player)

 print(amount)
end)
1 Like

It’s because you aren’t updating the amount variable. Set the amount in the event.

You need to define the variables within the function for them to be accurate.

local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	local Player = script.Parent.Parent.TextBox.Text
	local Amount = tonumber(script.Parent.Parent.Amount.Text)
	
	print(Player)
	print(Amount)
end)