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
 

Re: How do I do this?

Previous Thread :: Next Thread 
UnstableScript is not online. UnstableScript
Joined: 11 Dec 2015
Total Posts: 410
19 Dec 2015 09:48 AM
so, if I loadstring this

loadstring("while true do print(\"Hi!\")wait()end")()

Is there a way to intercept it later on, like save it as a variable and go loadstr:disconnect(), like this?

local loadstr = loadstring("while true do print(\"Hi!\")wait()end")()
wait(5)
loadstr:disconnect()
Report Abuse
CailThePuppy is not online. CailThePuppy
Joined: 11 Dec 2015
Total Posts: 91
19 Dec 2015 09:55 AM
Uh no.
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
19 Dec 2015 09:56 AM
There is not, you should know that.
Report Abuse
UnstableScript is not online. UnstableScript
Joined: 11 Dec 2015
Total Posts: 410
19 Dec 2015 09:59 AM
I didn't know of one, I was just asking. No need to be rude.

And I know there is, I just don't know how. Antiboomz0r did it.
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
19 Dec 2015 10:00 AM
I was not rude. I was saying that I thought you were smarter than this.
Report Abuse
UnstableScript is not online. UnstableScript
Joined: 11 Dec 2015
Total Posts: 410
19 Dec 2015 10:01 AM
Oh. It seemed like you were :/ hard to convey over the internet.

But anyways, any idea how he did it?
Report Abuse
CailThePuppy is not online. CailThePuppy
Joined: 11 Dec 2015
Total Posts: 91
19 Dec 2015 10:01 AM
There is not without implementing a custom wait function that yields your function and wrapping your loadstring in a coroutine.

woof
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
19 Dec 2015 10:01 AM
4 letters.

LASM
Report Abuse
UnstableScript is not online. UnstableScript
Joined: 11 Dec 2015
Total Posts: 410
19 Dec 2015 10:02 AM
What is that?
Report Abuse
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
19 Dec 2015 10:10 AM
Lua Assembly Machine Instructions
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
19 Dec 2015 10:48 AM
Okay okay okay okay, here's an intelligent answer. While I'm not entirely sure what you want :disconnect to do, I'm going to thoroughly explain what loadstring does, and how to utilize it.

First of all, loadstring takes a string, and turns it into a function, returning that function. Which is why you often see () right after. This is useful for if you only need the string to run once.


But what if you don't? What if you need this function in the future? Well it's quite simple really, because loadstring returns a function, simply assign the result of loadstring to a variable.

local loadstr = loadstring("print(\"Hi!\")")

loadstr()
loadstr()
loadstr()



But... You want a loop to run. And on :disconnect you want to break it...
Hmm.
Let's think.

Alright I got something.

So this plays on a multiple different concepts in Lua, but the basic idea is, make it a new thread, and break it when passed a specific argument (in this case, we'll use true).

local loadstr = loadstring("while not ({...})[1] do print(\"Hi!\")coroutine.yield()end")

loadstr = coroutine.create(loadstr)
coroutine.resume(loadstr)
coroutine.resume(loadstr, true) --We break it by passing true


Now what's the problem with this method? The simple fact that everytime we need to rerun the loop, we have to resume loadstr. Well this sucks.

But what if we used a global to break it instead...


finished = false
local loadstr = loadstring("while not finished do print(\"Hi!\")wait()end")

loadstr = coroutine.create(loadstr)
coroutine.resume(loadstr)
print("Let's wait 2 seconds")
wait(2)
print("Let's put this loop out of it's misery")
finished = true
wait(2)
print("It worked!")



Now let's wrap this up into a handy easy-to-use way of manipulating this:

Loops = {}
function LoadLoop(str)
local loadstr = coroutine.create(loadstring('print(Loops) print(coroutine.running()) while not Loops[coroutine.running()] do '..str..' wait()end'))
return setmetatable({Thread=loadstr}, {__call=function(t)coroutine.resume(t.Thread)end})
end
function EndLoop(loop)
Loops[loop.Thread] = true
end
function CleanUp()
for i,v in pairs(Loops) do
Loops[i] = nil
end
end


local x = LoadLoop('print"hi"')
x()
wait(2)
EndLoop(x)





Have fun (and thanks for the interesting use of my past 5-10 minutes.)
Report Abuse
UnstableScript is not online. UnstableScript
Joined: 11 Dec 2015
Total Posts: 410
19 Dec 2015 10:52 AM
Dude omg I will lick your shoes clean.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
19 Dec 2015 10:54 AM
XD
Report Abuse
inception101 is not online. inception101
Joined: 19 Dec 2010
Total Posts: 738
19 Dec 2015 11:08 AM
if Roblox.Player.warspyking ~= Enum.GlobalConflicts.Illuminati then
:Destroy(EverythingIHaveEverKnown)
end
Report Abuse
Waccsadac is not online. Waccsadac
Joined: 02 Jun 2012
Total Posts: 2440
19 Dec 2015 11:10 AM
Error in script: unexpected symbol near ':'


Waccsadac | Halosis Head of Innovation
Report Abuse
UnstableScript is not online. UnstableScript
Joined: 11 Dec 2015
Total Posts: 410
19 Dec 2015 11:20 AM
Okay, so I made this. How do I make it create the script? I already made the other functions I want, and sorta made the create function.

local Scripts = {}

local function CreateScript(Player, Name, Code)
Scripts[Player.Name][Name] = {Thread = true, Code = Code}
--Start it up??
end

local function StopAll(Player, Delete)
for Key, Value in next, Scripts[Player.Name] do
Value.Thread = true
end
if Delete then
Scripts[Player.Name] = {}
end
end

local function LoadScript(Player, Script)
local FoundScript = Scripts[Player.Name][Script]
if FoundScript then
FoundScript.Thread = false
else
SB:FireClient(Player, "Output", {Type = "Warn", Output = Script.." doesn't exist!"})
end
end

local function StopScript(Player, Script)
local FoundScript = Scripts[Player.Name][Script]
if FoundScript then
FoundScript.Thread = true
else
SB:FireClient(Player, "Output", {Type = "Warn", Output = Script.." doesn't exist!"})
end
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
19 Dec 2015 11:22 AM
I'll let you figure this one out in an effort to help you to improve :)
Report Abuse
UnstableScript is not online. UnstableScript
Joined: 11 Dec 2015
Total Posts: 410
19 Dec 2015 11:23 AM
But what if I can't get it..
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
19 Dec 2015 11:25 AM
Learn your crucial debugging skills.

If you look at my script it's really easy to see how it works. You can apply it in a script like yours with ease.
Report Abuse
UnstableScript is not online. UnstableScript
Joined: 11 Dec 2015
Total Posts: 410
19 Dec 2015 11:28 AM
Hmm, so I made this script. The problem is that I don't want them to have access to the global environment (It will be sandboxed), so I cannot give them access to Scripts to check if it is running. The other problem is that this loop-runs the code. I want the code to run, yes, but they have OPTIONAL looping. Like they have to add the loop if they want that.

so if I ran

s/print'hi'

It ideally wouldn't spam that unless I typed

s/while true do print'hi' end
Report Abuse
UnstableScript is not online. UnstableScript
Joined: 11 Dec 2015
Total Posts: 410
19 Dec 2015 11:29 AM
Oops, forgot the script. Here ya go.

local Scripts = {}

local function CreateScript(Player, Name, Code)
local LoadString = coroutine.create(loadstring([[
while not Scripts[coroutine.running()] do
]]..Code..[[
wait()
end
]]))
return setmetatable({Thread = LoadString}, {
__call = function(Script)
coroutine.resume(Script.Thread)
end,
})
end

local function StopAll(Player, Delete)
for Key, Value in next, Scripts[Player.Name] do
Value.Thread = true
end
if Delete then
Scripts[Player.Name] = {}
end
end

local function LoadScript(Player, Script)
local FoundScript = Scripts[Player.Name][Script]
if FoundScript then
FoundScript.Thread = false
else
SB:FireClient(Player, "Output", {Type = "Warn", Output = Script.." doesn't exist!"})
end
end

local function StopScript(Player, Script)
local FoundScript = Scripts[Player.Name][Script]
if FoundScript then
FoundScript.Thread = true
else
SB:FireClient(Player, "Output", {Type = "Warn", Output = Script.." doesn't exist!"})
end
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
19 Dec 2015 11:31 AM
You're going to have to find some other way of optional looping then.

Not to mention learn how to use setfenv appropriately to place the Loops in a sandboxed environment.



Anyway like I said, you want to improve, work on this. If Scripters do it all for you, you're not going to learn anything.
Report Abuse
UnstableScript is not online. UnstableScript
Joined: 11 Dec 2015
Total Posts: 410
19 Dec 2015 11:32 AM
Cmon bro. I literally have EVERYTHING else I need for this to work :/
Report Abuse
CailThePuppy is not online. CailThePuppy
Joined: 11 Dec 2015
Total Posts: 91
19 Dec 2015 12:28 PM
Mfw unfortunately I saw this coming and warspyking didn't because he is human

dog 2 human 0

lick
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
19 Dec 2015 02:18 PM
lmao y'all dumb
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