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

Why does it says "KamikazeJAM108867 is not a valid member of Players"?

Asked by 5 years ago

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)
0
Is this a LocalScript? Are you using FilteringEnabled? SchonATL 15 — 5y
0
Yes to both KamikazeJAM108867 38 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

Ad

Answer this question