How can I find a player no matter the string? So,
player = "player1"
--or
player = "PLAYER1"
both would be able to find "Player1", I tried FindFirstChild() doesn't seem to work..
How can I find a player no matter the string? So,
player = "player1"
--or
player = "PLAYER1"
both would be able to find "Player1", I tried FindFirstChild() doesn't seem to work..
There is more efficient ways to do this, but here it goes:
players = game.Players:getChildren() -- Pack players into a table
wantedPlayer = string.lower("SOMeNam3") -- Whatever you pass instead of this name will be converted to lowercase.
for _,v in pairs(players) do -- For every player (v) in players
if string.lower(v.Name) == wantedPlayer then -- If lowercase version of player name matches lowercase version of wantedPlayer
found = v -- Set the variable found equal to the player with the correct name
break -- End loop to save memory
end
end
-- Whatever you want to do with found player
Looks good. Nice answer.
Thank you.
Oh Hey buddy!
Nice to meet ya! So, you want find out a player no matter the name is written?
Well remember this before we can go onto... Let Player 1's name be PlayerofROBLOX Let Player 2's name be PlayerOFroblox
Now, in string manipulation, we have a pre-defined function called lower() What's the purpose? It gives you the string in a lowercase format, or less formal way xD
Like for example, If you apply the string.lower() function where string is the name of your player for instance, The function is going to return you the same name, but all the characters in it will be lowercase. In your case, it's gonna be a bit hard though.
For example, if you want to find the player and the function returns you the same string value for both players? (look up)
that means, Player1's name is gonna be just 'playerofroblox' and that applys to Player2's name too 'playerofroblox'
Hmmm, so possibly you want to make an admin list and then want to do stuff with only some people... For instance you want to make a script that will see if the player is on a list if players, and if he is, We do something to him (perhaps kick/ban him?)
Lets get coding
-- ServerScript placed in ServerScriptService
Allowed = {"Player1", "Player2"} -- Basically a list of people who are allowed to do something or not allowed LOL
function isAllowed(player) -- Define a function that checks if the passed parameter(player) is allowed to do something or not
for k, v in next, Allowed do -- loop through our table to see if a player matching
if v == player.Name then
return true -- Hey we got the player we want,
break -- so lets break the loop so it doesn't lag us :9
end
end
return false -- We didn't get our player here return false pls!
end
--[[
Now basically the above function is really useful for admin only stuff or even for making restricted doors and stuff =D
]]
Well, that's all that I can help,(Im sleepy so don't mind if I explained it bad or even made a bad answer)
Anyways, Cya around!
What's with all the LOLing and XDing?
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
http://wiki.roblox.com/index.php?title=Function_dump/String_manipulation&redirect=no