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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 08 Aug 2016 08:30 PM |
You want string.match.
local Whitespace, Digits = msg:match("/hat(%s*)(%d*)")
|
|
|
| Report Abuse |
|
|
OnlineOne
|
  |
| Joined: 14 Jul 2011 |
| Total Posts: 1193 |
|
|
| 08 Aug 2016 08:48 PM |
Can you please explain what this does?
--Online |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|