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

How do I make someone type in the player's user but not their full user?

Asked by 4 years ago

The script is a donation script where you can give players in-game currency. The thing is, they have to type in the player's full username which is a hassle. I don't know how to make it so you don't have to type in the player's full username.

Here is the script:

player = game.Players.LocalPlayer
currency = "Money"
recipient = ""
amount = 0
script.Parent.MouseButton1Click:Connect(function()
    recipient = script.Parent.Parent.Player.Text
    amount = tonumber(script.Parent.Parent.Amount.Text)
    if player.leaderstats[currency].Value >= tonumber(script.Parent.Parent.Amount.Text) then
        game.Players[recipient].leaderstats[currency].Value = game.Players[recipient].leaderstats[currency].Value + amount
        player.leaderstats[currency].Value = player.leaderstats[currency].Value - amount
        script.Parent.Text = "Payment Successful!"
        wait(1.5)
        script.Parent.Text = "Send"
    else
        script.Parent.Text = "You don't have enough cash to donate!"
        wait(2)
        script.Parent.Text = "Send"
    end
end)

1 answer

Log in to vote
0
Answered by
rabbi99 714 Moderation Voter
4 years ago

I always use this function. I didn't make it but it's really easy to use. It uses string.match in a different form.

local function GetPlayerFromString(nameString)
    local matches= {}
    for _, player in ipairs (game.Players:GetPlayers()) do
        if string.lower(player.Name):match(string.lower(nameString)) then
            table.insert(matches, player)
        end
    end
    if #matches== 1 then
        return matches[1]
    else
        return nil
    end
end

To use it:

local player = GetPlayerFromString("rab")
Ad

Answer this question