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: Super script - robux reward!

Previous Thread :: Next Thread 
hunte922 is online. hunte922
Joined: 28 May 2008
Total Posts: 6969
21 Nov 2012 05:04 PM
OK, here's my dilemma.

I need a script (ONLY ONE SCRIPT) that gathers all parts within a model and sets OnTouched functions to them.

And the reward?

The first person to post working code, if in Builder's Club, will receive 1kR$.

Notes:
- Only one script is allowed, inserting scripts into the parts within the model is not what I am asking for.
- Posting a link to a model that has what I am asking for, not made by the poster, will receive, if in Builder's Club, 500R$ instead of 1kR$.
- Payment will be done via t-shirt sales.
Report Abuse
nrscsy is not online. nrscsy
Joined: 09 Nov 2012
Total Posts: 465
21 Nov 2012 05:09 PM
FunctionFunction()
--your script
end

for _,v in pairs(workspace["Model"]:getChildren()) do
if v:IsA("BasePart") then
v.Touched:connect(FunctionFunction)
end
end
Report Abuse
ukwarrior6 is not online. ukwarrior6
Joined: 06 Sep 2009
Total Posts: 485
21 Nov 2012 05:12 PM
I don't request payment as this is ridiculously easy, ALSO DO NOT POST REQUESTS, i will give you a script this one time, but in future go to the "Let's make a deal forum" if you're planning on trading.


while wait() do
for index, child in pairs(script.Parent:GetChildren()) do

child.Touched:connect(function(Part)
print(child.Name.. "hit") -- if any part in the model is touched, this will print
end)

end
end


this should work alright, although i'm sure there's more efficient ways of doing it
Report Abuse
ukwarrior6 is not online. ukwarrior6
Joined: 06 Sep 2009
Total Posts: 485
21 Nov 2012 05:14 PM
Yeah, nrscsy's script is better :P
Report Abuse
L2000 is not online. L2000
Joined: 03 Apr 2008
Total Posts: 77448
21 Nov 2012 06:16 PM
And if the parts are inside a main model, but then deeper (For example, located within other models), use this:

function onTouched(hit)
-- Your code
end

function getAllPartsWithin(parent)
for i,v in pairs(parent:GetChildren()) do

if (v:IsA("Part")) then
v.Touched:connect(onTouched);
end

if (#v:GetChildren() > 0) then -- Run this on parts and others by ending first if
getAllPartsWithin(v);
end
end
end

getAllPartsWithin(workspace);

That's a simple code; using recursion (Running a function over and over, inside the function) it searches everything inside the parent for parts, then every part it finds gets the Touched event. Using that, you can have as many models as you want, and it will still find the parts (Unless it starts using up too much memory.. Don't worry about that, though).
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