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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: :sub() errors

Previous Thread :: Next Thread 
ASCORE is not online. 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
aminu54321 is not online. aminu54321
Joined: 08 Jun 2012
Total Posts: 1421
04 Dec 2013 08:33 PM
first
and hi
:)
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
04 Dec 2013 08:34 PM
My guess is that GetSplit is returning nil?

What error are you getting?
Report Abuse
ASCORE is not online. 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
aminu54321 is not online. aminu54321
Joined: 08 Jun 2012
Total Posts: 1421
04 Dec 2013 08:36 PM
y u no reply me?
Report Abuse
EchoReaper is online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
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 is not online. 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
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
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 is not online. 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
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