I have this block of code here and it takes the money perfectly but then prints this error, "KamikazeJAM108867 is not a valid member of Players" yet im playing the game. Can Someone please help me. Essentially i have a Gui with a playername and an amount, the amount works fine but it has a hard time sending the money to the right player "hence the error" Someone please help!!!
local player = game.Players.LocalPlayer script.Parent.Send.MouseButton1Down:Connect(function() print("clicked send") local playername = script.Parent.Playername.Text local amount = script.Parent.Amount.Text if player.leaderstats.Money.Value >= tonumber(amount) then player.leaderstats.Money.Value = player.leaderstats.Money.Value - tonumber(amount) wait(2) game.Players(playername).leaderstats.Money.Value = game.Players(playername).leaderstats.Money.Value + tonumber(amount) end if player.leaderstats.Money.Value < tonumber(amount) then script.Parent.Send.Text = "Not Enough Money" wait(1) script.Parent.Send.Text = "Send" end end)
Line 9. You are using brackets ()
instead of square brackets []
. Also, the TextBox
can receive any kind of text, so its Text
may not be a player name. For this, use FindFirstChild
.
if game:GetService('Players'):FindFirstChild(playername) then
That should work.