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

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

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

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")

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