Categories > Coding > Lua >
How to make a GetPlayerWithInitials Function
Posted
You know how in admin scripts, you don't need to do the full name of the player?
Like you type: ":kill rad" and it kills "radicalGuy52".
In order to do that, it just requires string manipulation with Limited Lua.
Heres an example:
You want to print to the output: a player's name. But you don't want to use the whole name.
In order to do that, we would do:
local target = "PlayerName"
for _, v in pairs(game:GetService('Players'):GetPlayers()) do
   if v.Name:lower():find(target:lower()) then
      print(v.Name);
   end
end
Change PlayerName to any part of the player's name (recommended: first four parts of it or so)
And it will print the player's exact name.
The base for this would be:
local target = "PlayerName"
for _, v in pairs(game:GetService('Players'):GetPlayers()) do
   if v.Name:lower():find(target:lower()) then
      -- Initialize your script here. 'v' is the Player object.
   end
end
Replied
Cancel
Post
Replied
Cancel
Post
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post