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 » Scripters
Home Search
 

String Manipulation

Previous Thread :: Next Thread 
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
08 Aug 2016 07:59 PM
local player = game.Players.LocalPlayer

player.Chatted:connect(function(message)
if message:sub(1, 5) == "/hat " then
local meshId = message:sub(message, message:find("/hat " + 1, "/hat (%d+)"))
local textureId = message:sub(message, message:find("/hat (%d+) " + 1, "/hat (%d+) (%d+)"))

local hat = game:GetService("InsertService"):LoadAsset(meshId):GetChildren()[1]
hat.Parent = character
hat.Handle.Mesh.TextureId = "http://www.roblox.com/asset/?id=" .. textureId
print("Adding hat " .. meshId .. " with texture " .. textureId .. " to " .. player.Name)
end
end)

--This script is supposed to create a hat. The meshID should go first, then the textureID should go second (Like this: /hat [meshID] [textureID]). However, I get the following error: Players.OnlineOne.PlayerGui.Commands:5: attempt to perform arithmetic on a string value Please help. Thanks.


--Online
Report Abuse
Laedere is online. Laedere
Joined: 17 Jun 2013
Total Posts: 23601
08 Aug 2016 08:03 PM
"/hat " + 1 is your problem
i assume you're trying to do "/hat " .. 1


Report Abuse
ReynnSolaris is not online. ReynnSolaris
Joined: 16 Jun 2013
Total Posts: 1345
08 Aug 2016 08:03 PM
+ 1 wahts that for man

;-(

just do this

if string.match(message,"/hat %d+%s%d+") ~= nil then

else

end

you kno


Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
08 Aug 2016 08:16 PM
How do I get the second number returned in the message:find?


--Online
Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
08 Aug 2016 08:22 PM
I don't think string:match() is what I want.

local meshId = message:sub(message, message:find(message, "/hat%s%d"), message:find(message, "/hat %d+"))
local textureId = message:sub(message, message:find(message, "/hat %d+%s%d"), message:find(message, "/hat %d+%s%d+"))

local hat = game:GetService("InsertService"):LoadAsset(meshId):GetChildren()[1]
hat.Parent = character
hat.Handle.Mesh.TextureId = "http://www.roblox.com/asset/?id=" .. textureId
print("Adding hat " .. meshId .. " with texture " .. textureId .. " to " .. player.Name)


--Online
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
08 Aug 2016 08:30 PM
You want string.match.

local Whitespace, Digits = msg:match("/hat(%s*)(%d*)")


Report Abuse
OnlineOne is not online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
08 Aug 2016 08:48 PM
Can you please explain what this does?


--Online
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
08 Aug 2016 08:50 PM
You didn't write the patterns yourself? That's okay I suppose.
string.match returns the match, or the captures if you use captures (Parentheses)


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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