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: Connect event to multiple parts through one script

Previous Thread :: Next Thread 
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
07 Apr 2014 03:26 PM
Hi, I am trying to make it so I can have an efficient way of putting a touched event into multiple parts, whilst only using one script. I think it's possible but I'm not sure.
I have made a script to find out if this works, but it is not working, and I think it's something to do with the touched event on the third line I put in. Can anyone help me debug my script, any help is appreciated. Thanks! (PS: I looked in the output but it gives no errors, so I'm stumped.)

Script:

for i,v in pairs(script.Parent:GetChildren()) do
if not v:IsA("Script") and not script.Parent:FindFirstChild("Explosion") and v.Transparency == 0 then
v.Touched:connect(function(hit)
local h = hit.Parent:FindFirstChild("Humanoid")
if h and h.Parent:FindFirstChild("Aura") then
local ex = Instance.new("Explosion", script.Parent)
local pos = script.Parent:GetModelCFrame()
ex.BlastPressure = 0
ex.BlastRadius = 10
ex.Position = pos.p
for _,part in pairs(script.Parent:GetChildren()) do
if not part:IsA("Explosion") or not part:IsA("Script") then
part.CanCollide = false
part.Transparency = 1
end
end
wait(2)
ex:Remove()
wait(60*2)
for _,parts in pairs(script.Parent:GetChildren()) do
if not parts:IsA("Explosion") or not parts:IsA("Script") then
parts.CanCollide = true
parts.Transparency = 0
end
end
end
end)
end
end

When life gives you lemons... BURN HIS HOUSE DOWN! >:D
Report Abuse
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
07 Apr 2014 04:53 PM
Bump?

When life gives you lemons... BURN HIS HOUSE DOWN! >:D
Report Abuse
Havemeat is not online. Havemeat
Joined: 08 Jan 2008
Total Posts: 18081
07 Apr 2014 04:58 PM
Are there any errors in the output? If so, can you paste them here?

Happy Scripting!
Havemeat
Report Abuse
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
08 Apr 2014 10:04 AM
@Have There's no errors on the output window. I'm kind of stumped.

When life gives you lemons... BURN HIS HOUSE DOWN! >:D
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
08 Apr 2014 10:08 AM
while wait() do
for I,v in pairs(script.Parent:GetChildren()) do
ypcall(function()
if v.Transparency == 0 and not script.Parent:findFirstChild("Explosion") then
v.Touched:connect(function(h)
if h.Parent:findFirstChild("Humanoid") then
--boommm
end
end
end)
Report Abuse
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
08 Apr 2014 10:21 AM
Ah, thanks island. I've never experimented with ypcall before, but still, thanks!

When life gives you lemons... BURN HIS HOUSE DOWN! >:D
Report Abuse
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
08 Apr 2014 10:24 AM
One question though, is the while wait() do at the start necessary?

When life gives you lemons... BURN HIS HOUSE DOWN! >:D
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
08 Apr 2014 10:25 AM
hint:when using ypcall(

its always

ypcall(function()
--code
end)

so like..

ypcall(function()
prinnnnnnnnnntttttt("sup[")
print "hi"
end)

output should show hi
Report Abuse
islandmaker2012 is online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
08 Apr 2014 10:26 AM
the while wait?
yes,very necessary..

otherwise,it instantly loops thru the objects,creates the touched event,ignores it and goes to next

looping it makes them all be able to be touched,otherwise it only runs once
Report Abuse
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
08 Apr 2014 10:28 AM
@island Alright. I'm going to try and use debounce with that script. Thanks.

When life gives you lemons... BURN HIS HOUSE DOWN! >:D
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