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: onChatted Problem?

Previous Thread :: Next Thread 
TacoBowls is not online. TacoBowls
Joined: 02 Mar 2009
Total Posts: 112
27 Jan 2013 02:03 AM
Eh, I'm not sure what exactly I did wrong. The problem is, the script is only working when their is only one possible command. If I add any others, the script breaks.

Heres a small portion of the script:

local derp = {["TacoBowls"] = true}
banned = {"Player"}

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

function onChatted(message, player)
if message:sub(1, 4) == "!ban" and derp[player.Name] then
victim = findPlayer(message:sub(5))
victim:Destroy()
end
table.insert(banned, victim.Name)
end

if message:sub(1, 5) == "!kill" and derp[player.Name] then
victim = findPlayer(message:sub(6))
victim.Character:BreakJoints()
end

game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(message) onChatted(message, player) end)
end)

So if I get rid of the kill command, it will work. Or if I get rid of the ban command, the kill will work. But not both together..

Thanks for any help.
Report Abuse
CokeCody is not online. CokeCody
Joined: 31 Mar 2010
Total Posts: 394
27 Jan 2013 02:08 AM
Instead of having a bunch of if statements and ends, just use elseif. Like:

    Game.Players.PlayerAdded:connect(function(player)
      if player.Name == "CokeCody" or player.Name == "TacoBowls" then
        player.Chatted:connect(function(chat)
          msg = chat:lower()
          if msg == "kill" then
            --Code that I don't feel like thinking about
          elseif msg == "kick" then
            --More code I don't feel like thinking about
          elseif msg == "msg" then
            --And some more code
          end
        end)  
      end
    end)

--This is just for help, you don't need to use my way.
Report Abuse
TacoBowls is not online. TacoBowls
Joined: 02 Mar 2009
Total Posts: 112
27 Jan 2013 10:22 AM
Bump^
Not sure if that really solved my problem though.
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
27 Jan 2013 10:41 AM
that should have fixed it...
Report Abuse
TacoBowls is not online. TacoBowls
Joined: 02 Mar 2009
Total Posts: 112
27 Jan 2013 10:58 AM
Well, I had to change parts of it and use strings instead, this is what I got after doing so:

banned = {}
Game.Players.PlayerAdded:connect(function(player)
if player.Name == "CokeCody" or player.Name == "TacoBowls" then
player.Chatted:connect(function(chat)
if string.sub(1, 4) == "ban/" then
victim = findPlayer(string.sub(5))
victim:Destroy()
table.insert(banned, victim.Name)
elseif
string.sub(1, 5) == "kill/" then
victim = findPlayer(string.sub(6))
victim.Character:BreakJoints()
end
end)
end
end)

Well, that doesn't work at least. Although, I've never actually done it that way either, so it's probably something I did. Do you see what's wrong here?
Report Abuse
CokeCody is not online. CokeCody
Joined: 31 Mar 2010
Total Posts: 394
27 Jan 2013 01:35 PM
"victim = findPlayer(string.sub(5))"

What is "findPlayer"?
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
27 Jan 2013 01:37 PM
function findPlayer(string)
for _,v in pairs(game:GetService'Players':GetPlayers'')do
if v.Name:lower'':sub(1,string:len'')==string:lower'' then
return v
end
end
end
Report Abuse
TacoBowls is not online. TacoBowls
Joined: 02 Mar 2009
Total Posts: 112
27 Jan 2013 01:38 PM
Derp, I forgot that I took away the function findPlayer I had inserted in the first script.

Thanks for all the help!
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