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)
1 Like
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)
3 Likes
Ok. Just to make sure I am putting it in the correct spot where would I put it?
Put it near the top of your script before the PlayerAdded function.
1 Like
Ok. I have put it above the PlayerAdded function and when I am putting “:givepoint kja 1” it is not working for me but I am getting no error messages.
This is what it looks like now.
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)
You have to use the Check function and pass NameOfPlayerToGivePoint
as a parameter. It will then return the player’s full name.
1 Like
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)
2 Likes
Thank you @alphajpeg and @COUNTYL1MITS for your help. It is working for me now.
Np, good luck with your project.
3 Likes