gogo6104
|
  |
| Joined: 10 Feb 2010 |
| Total Posts: 326 |
|
|
| 17 Nov 2016 03:37 PM |
Admin Scripts have the ability for you to just type SOME of the player's name, and it'll find the first player regarding that, sort of like FindFirstChild, but finding the FIRST child that has THAT in its name. How do you do this? Is it string.find? String Manipulation on the Wiki is sort of confusing :/
Masked_Beanie |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 17 Nov 2016 03:44 PM |
Here's a way:
local s = 'cac' -- first three characters of my username
local player = nil for i,v in pairs(game.Players:GetPlayers())do if string.sub(v.Name:lower(),1,s:len()) == s:lower() then player = v break end end |
|
|
| Report Abuse |
|
|
pidgey
|
  |
| Joined: 16 Jan 2008 |
| Total Posts: 2739 |
|
|
| 17 Nov 2016 03:45 PM |
| yes it is, if you want to understand it more i suggest you look up regular expression tutorials it looks confusing at first but its pretty simple |
|
|
| Report Abuse |
|
|
Ceirios
|
  |
| Joined: 01 Apr 2012 |
| Total Posts: 228 |
|
|
| 17 Nov 2016 03:46 PM |
--prefix=> --cmd ex is kill --excerpt below
local s,f=string.find(msg,msg:sub(6)) -- >kill including space after the l game.Players:FindFirstChild(f).Character:BreakJoints() |
|
|
| Report Abuse |
|
|
HlCOM
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3332 |
|
|
| 17 Nov 2016 03:57 PM |
game.Players.PlayerAdded:connect(function(plr) plr.Chatted:connect(function(msg) for i,v in ipairs (game.Players:GetPlayers()) do if string.lower(v.Name):match('^'..string.lower(msg)) then print('match') end end end) end)
:match searches for a match so like if i put
"1234"
it would look for anything with 1234 in it
but the ^ makes it so it's only searching for 1234 in the beginning of the string
and then string.lower makes everything lowercase so it's not caps-sensitive |
|
|
| Report Abuse |
|
|
gogo6104
|
  |
| Joined: 10 Feb 2010 |
| Total Posts: 326 |
|
|
| 17 Nov 2016 04:06 PM |
All of your answers were great, but I liked HICOM's best, it was the most simple and understanding. Thanks guys <3
Masked_Beanie |
|
|
| Report Abuse |
|
|
gogo6104
|
  |
| Joined: 10 Feb 2010 |
| Total Posts: 326 |
|
|
| 17 Nov 2016 04:24 PM |
Wait! HiCom, that works but, what if there's 2 users that have the same beginning name? the FOR statement will do the command to BOTH players, I don't want that ;c
Masked_Beanie |
|
|
| Report Abuse |
|
|
HlCOM
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3332 |
|
|
| 17 Nov 2016 04:35 PM |
rip
function Matches (msg) local Matches = 0 local wantedPlr for i,v in ipairs (game.Players:GetPlayers()) do if string.lower(v.Name):match('^'..string.lower(msg)) then print('match') wantedPlr = v Matches = Matches + 1 end end if Matches > 1 then print('More than 1 player with that possible name!') else --do stuff to wantedPlr end end
game.Players.PlayerAdded:connect(function(plr) plr.Chatted:connect(function(msg) Matches(msg) end) end)
probably a better way to do this but w/e
Once it is done scanning through player list, it checks to make sure there is not more than 1 match. if there is, then it will print the message
|
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 17 Nov 2016 04:36 PM |
| just use 'break' after it matches a player |
|
|
| Report Abuse |
|
|
gogo6104
|
  |
| Joined: 10 Feb 2010 |
| Total Posts: 326 |
|
|
| 17 Nov 2016 04:37 PM |
caca I love you
Masked_Beanie |
|
|
| Report Abuse |
|
|
HlCOM
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3332 |
|
|
| 17 Nov 2016 04:38 PM |
lol caca is the real MVP here
|
|
|
| Report Abuse |
|
|
gogo6104
|
  |
| Joined: 10 Feb 2010 |
| Total Posts: 326 |
|
| |
|
gogo6104
|
  |
| Joined: 10 Feb 2010 |
| Total Posts: 326 |
|
|
| 17 Nov 2016 04:40 PM |
I have one quick question for you guys, it's regarding events.
Recently I had the command set where you specify a target player, and I had it so what it does is FireAllClients(target), and each player has the script and the script for the player checks if the player's name is the target, how do I just fire it for the target like: FireClient()? I tried FireClient(target), but it says "Unable to cast value to object"
Masked_Beanie |
|
|
| Report Abuse |
|
|
HlCOM
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3332 |
|
|
| 17 Nov 2016 04:46 PM |
uhh post the full script on a new forum post too if this doesnt fix it
"target" should be the player object not a string value
so if you were doing like :FireClient('HlCOM') that wouldn't, you would have to do :FireClient(game.Players.HlCOM)
|
|
|
| Report Abuse |
|
|
HlCOM
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3332 |
|
| |
|
gogo6104
|
  |
| Joined: 10 Feb 2010 |
| Total Posts: 326 |
|
|
| 17 Nov 2016 04:48 PM |
that worked thanks bb
I didn't know if ROBLOX Lua straight up looked for the player named it, or you had to specify game.Players
<3
Masked_Beanie |
|
|
| Report Abuse |
|
|