generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Finding a players shortname

Previous Thread :: Next Thread 
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:05 PM
So like in Person299 admin commands where you can say like ff/pl to put a forcefield into player. How do I make the script find the players name shortened? I am making an admin commands and it breaks when I don't type the players name in full. Please help!
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:08 PM
bump.
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:12 PM
bump will post the erroring script if needed.
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:13 PM
Here's the script:

local admins = {"thedeathmaster01", "Player"}

game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(msg)
for i = 1, #admins do
if player.Name == admins[i] then

function findPlayer(name)
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Name:lower() == name:lower() then
return player
end
end
end

--Start commands

-- kick command
if msg:sub(1,2) == "k/" then
kp = findPlayer(msg:sub(3))
if game.Players[kp] ~= nil then
game.Players[kp]:Destroy()
end
end
--end kick command


--forcefield add command
if msg:sub(1,3) == "ff/" then
victim = findPlayer(msg:sub(4))
if game.Players[victim] ~= nil then
Instance.new("ForceField", Workspace[victim])
end
end
--end forcefield add command

--start remove forcefield command
if msg:sub(1,5) == "unff/" then
unvictim = findPlayer(msg:sub(6))
if game.Players[unvictim] ~= nil then
for _,v in pairs(Workspace[victim]:GetChildren()) do
if v:IsA("ForceField") then v:Destroy()
end
end
end
end
--end remove forcefield command

--Default end marks
end
end
end)
end)
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:17 PM
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:19 PM
no one, huh?
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:21 PM
b u m p
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
16 Sep 2012 04:22 PM
function findPlayer(name)
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Name:lower() == name:lower() then
return player
end
end
end

You can change this line:
if player.Name:lower() == name:lower() then

To:
if player.Name:lower():find(name:lower()) then

That trys to see if the name you typed is _any part_ of a player's name, rather than just equal to it. Which will make stuff like "loc" match the player "blockguy".
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:23 PM
@stravant, thanks, I'll try that. I got the findPlayer function from

http://wiki.roblox.com/index.php/How_To:_Admin_Commands
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:26 PM
Did that, but I am still getting the same error:

Workspace.Script:40: bad argument #2 to '?' (string expected, got userdata)
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:27 PM
Current script:

local admins = {"thedeathmaster01", "TechnologyKing"}

game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(msg)
for i = 1, #admins do
if player.Name == admins[i] then

function findPlayer(name)
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Name:lower():find(name:lower()) then -- CHANGED THIS!
return player
end
end
end

--Start commands

-- kick command
if msg:sub(1,2) == "k/" then
kp = findPlayer(msg:sub(3))
if game.Players[kp] ~= nil then
game.Players[kp]:Destroy()
end
end
--end kick command


--forcefield add command
if msg:sub(1,3) == "ff/" then
victim = findPlayer(msg:sub(4))
if game.Players[victim] ~= nil then
Instance.new("ForceField", Workspace[victim])
end
end
--end forcefield add command

--start remove forcefield command
if msg:sub(1,5) == "unff/" then
unvictim = findPlayer(msg:sub(6))
if game.Players[unvictim] ~= nil then
for _,v in pairs(Workspace[victim]:GetChildren()) do
if v:IsA("ForceField") then v:Destroy()
end
end
end
end
--end remove forcefield command

--Default end marks
end
end
end)
end)
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:35 PM
ba,p
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
16 Sep 2012 04:37 PM
instead of game.Players[victim], just use victim

¬ Scripter Tier-2, LuaLearners Elite ♣ scripting teacher/freelance worker ♣ send me trade requests!
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:43 PM
but victim is just the players name
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
16 Sep 2012 04:43 PM
but it's not...

¬ Scripter Tier-2, LuaLearners Elite ♣ scripting teacher/freelance worker ♣ send me trade requests!
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:46 PM
Can you fix the script for me?
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 04:49 PM
bump
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 05:03 PM
be ue em pe
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 05:28 PM
Someone please help!
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 05:32 PM
If I don't get a reply within 5 minutes, I'll make a new thread and f5 this one.
Report Abuse
adark is not online. adark
Joined: 13 Jan 2008
Total Posts: 6412
16 Sep 2012 05:37 PM
You have already been given your solution. If you don't want to try it that's your problem.
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
16 Sep 2012 05:51 PM
I don't understand what they said to do.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
16 Sep 2012 06:25 PM
It's just like DoomBringer said:

The way you have it working right now, `victim` _is_ the player, not the player's name. Replace what you have right now with `victim` for the player and `victim.Character` for their character.
Report Abuse
doombringer42 is not online. doombringer42
Joined: 13 Nov 2007
Total Posts: 5445
16 Sep 2012 06:39 PM
don't call me DoomBringer

i'm not MrDoomBringer, i'm doombringer42 ;-;

¬ Scripter Tier-2, LuaLearners Elite ♣ scripting teacher/freelance worker ♣ send me trade requests!
Report Abuse
builderman1171 is not online. builderman1171
Joined: 27 Mar 2010
Total Posts: 1595
16 Sep 2012 06:41 PM
umg i'm loling so hard at what doombringer42 said in reply to stravant. WAY TO SHOW ADMINS WE DISLIKE THEM! :D

-> Siggy pooped by the power of Ponies <-
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image