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: ForceField

Previous Thread :: Next Thread 
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
01 Apr 2013 08:03 PM
function onTouched(hit)
Instance.new("ForceField",game.Workspace.Player1)
end

is there something I did wrong?
Report Abuse
StormRecon is not online. StormRecon
Joined: 15 Aug 2010
Total Posts: 2214
01 Apr 2013 08:03 PM
There's no connection line

Report Abuse
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
01 Apr 2013 08:05 PM
would that be
game.Workspace.Player1?
Report Abuse
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
01 Apr 2013 08:07 PM
Bump
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
01 Apr 2013 08:10 PM
Game.Workspace.Part.Touched:connect(functionnamehere)
Report Abuse
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
01 Apr 2013 08:11 PM
OH YEAH! THANKS GUYS!
Report Abuse
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
01 Apr 2013 08:16 PM
Touched is not a valid member of Model

:(
Report Abuse
StormRecon is not online. StormRecon
Joined: 15 Aug 2010
Total Posts: 2214
01 Apr 2013 08:24 PM
Put it inside a brick
Report Abuse
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
01 Apr 2013 08:26 PM
Won't work :(
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
01 Apr 2013 08:33 PM
full script would be placed in a part, not a model.

script.Parent.Touched:connect(function(h)
if h.Parent:FindFirstChild("Humanoid") ~= nil then
Instance.new("ForceField",h.Parent)
end
end)

I used an anonymous function where I do not explicitly define the function as like
function onTouched(hit)
or something like that.
I checked for a humanoid in the 2nd line to make sure it was a person that hit the brick.
the first line is essentially the function line and the connection line combined, the anonymous function i said earlier.
Report Abuse
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
01 Apr 2013 08:34 PM
Teach me more master o3o
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
01 Apr 2013 08:38 PM
There is a lot to teach and learn. I suppose I was where you are at some point, wondering the same things you wonder. While I cannot teach you all the knowledge my brain encompasses, I will most certainly answer specific questions, because I know how frustrating it can be when you are confused and cant get answers. This goes for anyone, really.
Report Abuse
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
01 Apr 2013 08:39 PM
script.Parent.Touched:connect (function(onTouched)
if h.Parent:FindFirstChild("Humanoid") ~= nil then
Instance.new("ForceField",h.Parent)
end
end)

it said this in the output

19:39:18.462 - script.Parent.Touched:connect (function(onTouched)
if h.Par:1: attempt to index global 'script' (a nil value)
19:39:18.463 - Script "script.Parent.Touched:connect (function(o
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
01 Apr 2013 08:45 PM
Not sure why it said that, but you can't say onTouched inside of function there and then also say h on the line below, I used that as a variable, because the Touched event returns a part, h, but in your case you named it onTouched, and then called it h later. The thing inside function in anonymous functions is not the name, otherwise it wouldn't be anonymous. You use anonymous functions if that function only occurs once, because when you regularly define a function
function onTouched(part)
you can call
onTouched() as much as you want throughout the script
Hope it makes sense. Essentially what I'm saying is, you can't call a function if it doesn't have a name
Report Abuse
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
01 Apr 2013 08:49 PM
I don't understand anything you said, sorry....
Report Abuse
12packkid is not online. 12packkid
Joined: 24 Jun 2011
Total Posts: 1418
01 Apr 2013 08:54 PM
I get frustrated when you want to download something ultra cool, there is a survey, you complete it and then it says it's still locked.

†† -1 2 P A C K K I D-* ^◕‿◕^* - ❤True friendship is not what matters ❤-††
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
01 Apr 2013 08:57 PM
I can't explain it much differently so rather ask me specific questions about what i said
Report Abuse
OKevinO is not online. OKevinO
Joined: 05 May 2010
Total Posts: 1036
01 Apr 2013 10:59 PM
@Shomex

if you saying:
script.Parent.Touched:Connect(function(OnTouched) -- OnTouched.. the problem.
if OnTouched.Parent:FindFirstChild("Humanoid") ~= nil then
Instance.new("ForceField",OnTouched.Parent)
end
end)

if you name the argument script.Parent.Touched:connect as "OnTouched" then you would use that argument to verify if the humanoid is real or not.

killjoy37 named the function as "h" so he wrote it like this:
"script.Parent.Touched:Connect(function(h)
if h.Parent:FindFirstChild("Humanoid") ~= nil then
Instance.new("ForceField",h.Parent)
end
end)

that is the simplest way to really explain it...
Report Abuse
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
02 Apr 2013 04:49 PM
script.Parent.Touched:Connect(onTouched)
if OnTouched.Parent:FindFirstChild("Humanoid") ~= nil then
Instance.new("ForceField",OnTouched.Parent)
end
end)

..?
Report Abuse
btft is not online. btft
Joined: 19 Feb 2011
Total Posts: 1512
02 Apr 2013 05:14 PM
what has gone into u people!

function onTouched(plx)
if plx.Parent:FindFirstChild("Humanoid") ~= nil then
Instance.new("ForceField",plx.Parent)
end
end
script.Parent.Touched:connect(onTouched)
Report Abuse
btft is not online. btft
Joined: 19 Feb 2011
Total Posts: 1512
02 Apr 2013 05:16 PM
Added a FF spam prevention line.

function onTouched(plx)
if plx.Parent:FindFirstChild("Humanoid") ~= nil then
if plx.Parent:FindFirstChild("ForceField") == nil then --FF spam prevention
Instance.new("ForceField",plx.Parent)
end
end
end
script.Parent.Touched:connect(onTouched)
Report Abuse
Shomex is not online. Shomex
Joined: 04 Sep 2012
Total Posts: 690
02 Apr 2013 05:54 PM
I thought the line went on the bottom!
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
02 Apr 2013 06:33 PM
He's not familiar with anonymous notation. And that isn't the way to prevent forcefield spam, you need a debouncer, which works by preventing the placement of a forcefield after one has just been placed for a set amount of time. Use exactly what I wrote, and if you want a debouncer I'll add that in after this post.
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
02 Apr 2013 06:36 PM
debouncer = false
script.Parent.Touched:connect(function(h)
if debouncer == false then
debouncer = true
if h.Parent:FindFirstChild("Humanoid") ~= nil then
Instance.new("ForceField",h.Parent)
end
wait(1)
debouncer = false
end)

See how it works? It only checks for a humanoid if debouncer is false, and then it makes it true so if the function is run again it won't make it past the first if statement. Towards the end you see a wait(1), meaning it waits one second and then makes debouncer false again so it can allow the program to run normally again.
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