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: Simple sb script

Previous Thread :: Next Thread 
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
26 Dec 2012 11:21 PM
game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(Message)
if(Message:sub(1,7)=="script/")then
loadstring(Message:sub(8))()
end
end)
end)

---------------------------------------

Here we have a simple and working sb script (credit to topcop1) however i'd like it to point out any errors if you paste the script in the chat bar and it does not work, how would I do so?

Could I use "error"?

http://wiki.roblox.com/index.php/Function_Dump/Core_Functions#error


??


Any help would absolutely be appreciated!
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
26 Dec 2012 11:26 PM
game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(Message)
if Message:match("^script/") then
local s, err = coroutine.resume(coroutine.create(loadstring(Message:sub(8))))
Instance.new("Message",Workspace).Text=err --or however you want to display it; but the variable 'err' is the error message
end
end)
end)
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
26 Dec 2012 11:31 PM
Lemme change that

game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(Message)
if Message:match("^script/") then
local s, err = coroutine.resume(coroutine.create(loadstring(Message:sub(8))))
if not s then
Instance.new("Message",Workspace).Text=err --or however you want to display it; but the variable 'err' is the error message
end
end
end)
end)
Report Abuse
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
26 Dec 2012 11:40 PM
Hmm didn't work, I don't understand corutines but here's mine -- that didn't work.

game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(Message)
if(Message:sub(1,7)=="script/")then
local s,error = (coroutine.create(loadstring(Message:sub(8))()))
if not s then
Instance.new("Hint", player.PlayerGui).Text=error
end
end
end)
end)
----------

I was attempting to try and learn off of you. :(
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
26 Dec 2012 11:43 PM
game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(Message)
if Message:match("^script/") then
local s, err = coroutine.resume(coroutine.create(loadstring(Message:sub(8))))
if not s then
Instance.new("Message",player.PlayerGui).Text=err
end
end
end)
end)

You have to resume a coroutine. If you only create it and never use it, it's garbage.
Report Abuse
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
26 Dec 2012 11:45 PM
I'm really sorry for making you do more but it's not working..


game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(Message)
if(Message:sub(1,7)=="script/")then
local s,error = coroutine.resume(coroutine.create(loadstring(Message:sub(8))()))
if not s then
Instance.new("Hint", player.PlayerGui).Text=error
end
end
end)
end)
------------------

It is in a regular script btw.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
26 Dec 2012 11:48 PM
I tested mine and it works perfectly (except I forgot to change "Message" to "Hint"). Are you sure you're running it correctly?
Report Abuse
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
26 Dec 2012 11:50 PM
Yes, I put it in a script in the workspace, go to my game and say "script/print("ddd)" and it doesn't say error: Unfinished string.

I want it to print any errors wrong with the code.
Report Abuse
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
26 Dec 2012 11:59 PM
bump? :(
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
27 Dec 2012 12:05 AM
I made a dumb mistake. But, I tested this and I guarantee it works:

game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(Message)
if Message:match("^script/") then
local s, err = loadstring(Message:match("script/(.+)"))
if not s then
Instance.new("Hint",player.PlayerGui).Text=err
end
end
end)
end)
Report Abuse
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
27 Dec 2012 12:07 AM
Okay, it works.


Ty for keeping calm and not freaking out at me for me being such a noob.
Report Abuse
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
27 Dec 2012 12:11 AM
May I ask one more question?


How can I understand this line:


("script/(.+)"))

.+ -- I don't get that?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
27 Dec 2012 12:16 AM
http://wiki.roblox.com/index.php/String_patterns
http://wiki.roblox.com/index.php/Function_Dump/String_Manipulation#string.match

If you were also wondering about "^script/", the ^ anchors the pattern to the beginning, so string.match("^script/") basically means "does the string start with "script/"? This is always better than string.find, because then you don't have to worry about numbers and lengths.
Report Abuse
ninja5566 is not online. ninja5566
Joined: 14 Jan 2009
Total Posts: 5233
27 Dec 2012 12:16 AM
Woah, I learned alot..


game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(Message)
if (Message:sub(1,7)=="script/") then
local s, err = loadstring(Message:sub(8))
if not s then
a = game.Lighting.ErrorGui:clone()
a.Parent = player.PlayerGui
a.Text = err
wait(2)
a:Destroy()
end
end
end)
end)
-------------------------------------------

I made it more easier to my understanding, anyways thanks for helping!
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