ASCORE
|
  |
| Joined: 19 Oct 2013 |
| Total Posts: 246 |
|
|
| 04 Dec 2013 08:32 PM |
Ok, so I am creating an admin commands script and I am trying to make a command change;me;kos;7 and I cant find anywhere to fix my :sub() errors. Local PlrTab and Local LStat are read from the MSG but LStatAmount is ignored for some reason.
Command("Change", 2, "Changes a players stats", function(Msg, Speaker) local Split = GetSplit(Msg) local PlrTab = getPlayer(Speaker, Msg:sub(1, Split - 1)) local LStat = Msg:sub(Split + 1) local LStatAmount = Msg:sub(Split + 2) for i, v in pairs(PlrTab) do if v and v.leaderstats then Ping("Leaderstats exist on line 1863", Speaker, 5) v.leaderstats[LStat].Value = LStatAmount end end end) |
|
|
| Report Abuse |
|
|
| |
|
|
| 04 Dec 2013 08:34 PM |
My guess is that GetSplit is returning nil?
What error are you getting? |
|
|
| Report Abuse |
|
|
ASCORE
|
  |
| Joined: 19 Oct 2013 |
| Total Posts: 246 |
|
|
| 04 Dec 2013 08:36 PM |
The GetSplit works up unitl change;me but I need it to go upto change;me;cash;5 Splits are the ; BTW |
|
|
| Report Abuse |
|
|
| |
|
|
| 04 Dec 2013 08:39 PM |
There is no :Sub() method in Lua, but there is string.sub() which effectively does the same thing. string.sub() takes two required parameters, and a third optional parameter. The first parameter is the string which you are wanting to substring; the second parameter is the position of the first letter of your substring, while the third, optional parameter is the ending number of the string. If you leave off the third parameter, the script will just take everything from the first number until the end of the string.
Examples:
print(string.sub("Hello",2,4)) >> ell print(string.sub("ROBLOX",3)) >> BLOX
Also, unlike some other languages such as Java and C++, in Lua, the first position of a string is 1 -- not 0. So in the string "Hello", "H" would be 1, "e" would be 2, and so on. |
|
|
| Report Abuse |
|
|
ASCORE
|
  |
| Joined: 19 Oct 2013 |
| Total Posts: 246 |
|
|
| 04 Dec 2013 08:43 PM |
function GetSplit(Msg) return Msg:find(Bet) or nil end
Bet = ";" |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2013 08:51 PM |
Command("Change", 2, "Changes a players stats", function(Msg, Speaker) local Split = GetSplit(Msg) local PlrTab = getPlayer(Speaker, Msg:sub(1, Split - 1)) local LStat = Msg:sub(Split:sub(2),Split:sub(2):GetSplit()-1) local LStatAmount = Split:sub(2):sub(Split:sub(2)+1) for i, v in pairs(PlrTab) do if v and v.leaderstats then Ping("Leaderstats exist on line 1863", Speaker, 5) v.leaderstats[LStat].Value = LStatAmount end end end) |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2013 08:59 PM |
Command("Change", 2, "Changes a players stats", function(Msg, Speaker) local Split = GetSplit(Msg) local PlrTab = getPlayer(Speaker, Msg:sub(1, Split - 1)) local LStat = Split:sub(2,Split:sub(2,GetSplit()-1)) local LStatAmount = Split:sub(2):sub(Split:sub(2):GetSplit()+1) for i, v in pairs(PlrTab) do if v and v.leaderstats then Ping("Leaderstats exist on line 1863", Speaker, 5) v.leaderstats[LStat].Value = LStatAmount end end end) |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2013 09:07 PM |
Command("Change", 2, "Changes a players stats", function(Msg, Speaker) local Stuff = {} for n in Msg:gmatch(".-;") do table.insert(Stuff,n:sub(1,#n-1)) end local Player,Stat,Amount = Stuff[1],Stuff[2],Stuff[3] Player = Player and getPlayer(Player) if Player and Stat and Amount then Player.leaderstats[Stat].Value = Amount end end) |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2013 09:08 PM |
Command("Change", 2, "Changes a players stats", function(Msg, Speaker) local Stuff = {} for n in Msg:gmatch(".-;") do table.insert(Stuff,n:sub(1,#n-1)) end local Player,Stat,Amount = Stuff[1],Stuff[2],Stuff[3] Player = Player and getPlayer(Speaker,Player) if Player and Stat and Amount then Player.leaderstats[Stat].Value = Amount end end |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2013 09:15 PM |
Command("Change", 2, "Changes a players stats", function(Msg, Speaker) local Stuff = {} for n in (Msg..(";")):gmatch(".-;") do table.insert(Stuff,n:sub(1,#n-1)) end local Player,Stat,Amount = Stuff[1],Stuff[2],Stuff[3] Player = Player and getPlayer(Speaker,Player) if Player and Stat and Amount then Player.leaderstats[Stat].Value = Amount end end |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2013 09:17 PM |
Command("Change", 2, "Changes a players stats", function(Msg, Speaker) local Stuff = {} for n in (Msg..(";")):gmatch(".-;") do table.insert(Stuff,n:sub(1,#n-1)) end local Player,Stat,Amount = Stuff[1],Stuff[2],Stuff[3] Player = Player and getPlayer(Speaker,Player) if Player and Stat and Amount then for P in pairs(Player) do P.leaderstats[Stat].Value = Amount end end end |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2013 09:22 PM |
--DIS ONE!!!!!!!!!
Command("Change", 2, "Changes a players stats", function(Msg, Speaker) local Stuff = {} for n in (Msg..(";")):gmatch(".-;") do table.insert(Stuff,n:sub(1,#n-1)) end local Player,Stat,Amount = Stuff[1],Stuff[2],Stuff[3] Player = Player and getPlayer(Speaker,Player) if Player and Stat and Amount then for _,P in pairs(Player) do P.leaderstats[Stat].Value = Amount end end end |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2013 09:28 PM |
--AND NOW THIS>
Command("Change", 2, "Changes a players stats", function(Msg, Speaker) local Stuff = {} for n in (Msg..(";")):gmatch(".-;") do table.insert(Stuff,n:sub(1,#n-1)) end local Player,Stat,Amount = Stuff[1],Stuff[2],Stuff[3] Player = Player and getPlayer(Speaker,Player) if Player and Stat and Amount then for _,P in pairs(Player) do if P:FindFirstChild("leaderstats") then for _, sin pairs(Player.leaderstats:GetChildren()) do if s.Name("^"..Stat:lower()) then s.Value = Amount end end end end end end) |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2013 09:29 PM |
--Never mind...This one
Command("Change", 2, "Changes a players stats", function(Msg, Speaker) local Stuff = {} for n in (Msg..(";")):gmatch(".-;") do table.insert(Stuff,n:sub(1,#n-1)) end local Player,Stat,Amount = Stuff[1],Stuff[2],Stuff[3] Player = Player and getPlayer(Speaker,Player) if Player and Stat and Amount then for _,P in pairs(Player) do if P:FindFirstChild("leaderstats") then for _, s in pairs(Player.leaderstats:GetChildren()) do if s.Name:lower():match("^"..Stat:lower()) then s.Value = Amount end end end end end end) |
|
|
| Report Abuse |
|
|
ASCORE
|
  |
| Joined: 19 Oct 2013 |
| Total Posts: 246 |
|
|
| 04 Dec 2013 09:31 PM |
I added a message "Created by Notsopwnedg" Thank you so much! |
|
|
| Report Abuse |
|
|