I have made a command that can give players points in the game. I am wanting to make it where I don’t have to type the whole username in and I could just type the first few characters. Could anyone help me with this?
Script
local GroupId = 5952287 --GroupId
local MinimumRankToUseCommand = 250 --Rank to use this command
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
Player.Chatted:Connect(function(Message)
local Words = string.split(Message, " ")
if Words[1] == ":givepoint" then
local NameOfPlayerToGivePoint = Words[2]
local AmountOfPointsToGive = Words[3]
local PlayerToGivePoint = game.Players:FindFirstChild(NameOfPlayerToGivePoint)
if PlayerToGivePoint then
PlayerToGivePoint.leaderstats.Points.Value = PlayerToGivePoint.leaderstats.Points.Value + AmountOfPointsToGive
end
end
end)
end
end)
You can get the rest of a players username by looping through each player in game and then using string.sub to check if your parameter = player name.
Here is a function I made for it:
function Check(name)
name = name:lower()
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name:lower():sub(1,#name) == name then
return v.Name
end
end
end
Check(NameOfPlayerToGivePoint)
local GroupId = 5952287 --GroupId
local MinimumRankToUseCommand = 250 --Rank to use this command
function Check(name)
name = name:lower()
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name:lower():sub(1,#name) == name then
return v.Name
end
end
end
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
Player.Chatted:Connect(function(Message)
local Words = string.split(Message, " ")
if Words[1] == ":givepoint" then
local NameOfPlayerToGivePoint = Words[2]
local AmountOfPointsToGive = Words[3]
local PlayerToGivePoint = game.Players:FindFirstChild(NameOfPlayerToGivePoint)
if PlayerToGivePoint then
PlayerToGivePoint.leaderstats.Points.Value = PlayerToGivePoint.leaderstats.Points.Value + AmountOfPointsToGive
end
end
end)
end
end)
local GroupId = 5952287 --GroupId
local MinimumRankToUseCommand = 250 --Rank to use this command
function Check(name)
name = name:lower()
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name:lower():sub(1,#name) == name then
return v
end
end
end
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
Player.Chatted:Connect(function(Message)
local Words = string.split(Message, " ")
if Words[1] == ":givepoint" then
local NameOfPlayerToGivePoint = Words[2]
local AmountOfPointsToGive = Words[3]
local PlayerToGivePoint = Check(NameOfPlayerToGivePoint)
if PlayerToGivePoint then
PlayerToGivePoint.leaderstats.Points.Value = PlayerToGivePoint.leaderstats.Points.Value + AmountOfPointsToGive
end
end
end)
end
end)