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
 

Can I do this with Touched event?

Previous Thread :: Next Thread 
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
16 Jun 2014 08:57 PM
So let's say if I wanted there to be no explosion if a player touches but only when a specific part touches it, would it be like this?

function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
return
if hit.Name == "Boom" then
Instance.new("Explosion") --ect...
end

script.Parent.Touched:connect(onTouched)
Report Abuse
TheShoeBox is not online. TheShoeBox
Joined: 20 Aug 2010
Total Posts: 5022
16 Jun 2014 09:04 PM
function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
return
elseif hit.Name == "Boom" then
Instance.new("Explosion") --ect...
end

script.Parent.Touched:connect(onTouched)

Use elseif
I'm not sure if there's a space inbetween those two words.
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
16 Jun 2014 09:07 PM
Ok, also at the return part, should there be an end like this? :

if hit.Parent:FindFirstChild("Humanoid") then
return end
Report Abuse
TheShoeBox is not online. TheShoeBox
Joined: 20 Aug 2010
Total Posts: 5022
16 Jun 2014 09:09 PM
I actually asked myself the same question when you did that,

but I believe that you don't have to.

Using the elseif statement will make it one big funciton, so then the end would go at the bottom

I used to always use

return
end

so I got confused too... But I believe the end goes at the end, because otherwise the elseif is pointless.
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
17 Jun 2014 01:12 AM
But just wondering, can I still just use the 'if' statement and not the elseif?
Report Abuse
TheShoeBox is not online. TheShoeBox
Joined: 20 Aug 2010
Total Posts: 5022
17 Jun 2014 01:31 AM
Well I think you need two ends if you don't use elseif.

But yeah, you could do that.
Report Abuse
Locard is not online. Locard
Joined: 13 Apr 2014
Total Posts: 3516
17 Jun 2014 01:34 AM

script.Parent.Touched:connect(function(hit)
if hit.Name == "Boom" then
Instance.new("Explosion) --ect...
end
end)

You don't need to check if there is a person there in the first place. Just make sure that whatever you 'hit' has a specific property not relating to a person. In this case, naming it "Boom" would be pretty much settle it.
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