|
| 21 Dec 2014 03:30 PM |
Is there a way for an ontouch function to work for all things that have the same name O.o
Because i know you can do this for the last line
game.Workspace.Curve.SlideSit.Touched:connect(onTouched)
to define what it has to touch
But is there a way for it to work on any part named SlideSit? or just for something with the same name? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 21 Dec 2014 03:38 PM |
local function Iter(o) for k,v in pairs(o:GetChildren()) do Iter(v) if v.Name=="SlideSit" then v.Touched:connect(somefunction) end end end Iter(workspace) |
|
|
| Report Abuse |
|
|
|
| 21 Dec 2014 03:45 PM |
Thank you so much elun for trying to help but it gave this error
16:43:16.589 - Attempt to connect failed: Passed value is not a function 16:43:16.590 - Script 'Players.Player1.PlayerGui.LocalScript', Line 5 - local Iter 16:43:16.590 - Script 'Players.Player1.PlayerGui.LocalScript', Line 9 16:43:16.590 - Stack End |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
|
| 21 Dec 2014 03:51 PM |
| I don't think there is a 'somefunction' function defined, and that's why it's complaining. |
|
|
| Report Abuse |
|
|
Ojia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 650 |
|
|
| 21 Dec 2014 03:52 PM |
Try this
for i,v in pairs (game.Workspace:GetChildren()) do if(v.Name == "Name here") then -- Blah blah blah end |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 21 Dec 2014 03:54 PM |
| Dude that was even worse than mine, and it only does the top level. |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Dec 2014 03:57 PM |
I guess i will just do it the long way oh well
function onTouched(hit) game.Players.LocalPlayer.Character.Humanoid.Sit = true end game.Workspace.SlideSit.Touched:connect(onTouched)
function onTouched(hit) game.Players.LocalPlayer.Character.Humanoid.Sit = true end game.Workspace.SlideSitTwo.Touched:connect(onTouched)
function onTouched(hit) game.Players.LocalPlayer.Character.Humanoid.Sit = true end game.Workspace.SlideSitThree.Touched:connect(onTouched)
....ect ... 37 more to go xD |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 21 Dec 2014 03:58 PM |
function onTouched(hit) game.Players.LocalPlayer.Character.Humanoid.Sit = true end game.Workspace.SlideSit.Touched:connect(onTouched)
function onTouched(hit) game.Players.LocalPlayer.Character.Humanoid.Sit = true end game.Workspace.SlideSitTwo.Touched:connect(onTouched)
What are you doing moron |
|
|
| Report Abuse |
|
|
|
| 21 Dec 2014 03:59 PM |
coolfun:
In your example above, you redefine the same function with the same code in it. You don't need to do this.
If, for example, you wanted a variable, you wouldn't re-make the variable every time you wanted to use it. Functions are essentially variables, so the same logic applies.
function onTouched(hit) game.Players.LocalPlayer.Character.Humanoid.Sit = true end
game.Workspace.SlideSit.Touched:connect(onTouched) game.Workspace.SlideSitTwo.Touched:connect(onTouched) game.Workspace.SlideSitThree.Touched:connect(onTouched) |
|
|
| Report Abuse |
|
|
|
| 21 Dec 2014 04:01 PM |
>:omg you can double define a function >:O i never knew that THANK YOU SO MUCH XD
this is definitely a very helpful piece of coding info |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 21 Dec 2014 04:01 PM |
(Hint hint) Stick this at the top of my script, before the function Iter bit
function somefunction(hit) game.Players.LocalPlayer.Character.Humanoid.Sit = true end |
|
|
| Report Abuse |
|
|
|
| 21 Dec 2014 04:12 PM |
@elun how am i a moron O.o
i am not very experienced at scripting and i am still trying to learn
Logic said if i can not have it work with the same name then simple redo it with a different name each time ..... how is that stupid ..........
it is not my fault for being new O.o I spent most of my time building anyways I very highly request builder |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 21 Dec 2014 04:14 PM |
| You're a moron because you learn what instead of why. You do stuff because it works, not because you know why or how it works. |
|
|
| Report Abuse |
|
|
|
| 21 Dec 2014 04:20 PM |
I do know how what I did works O.o
I made a function I told it what to do i ended it and then i defined it O.o
I may not know all the rules and limitations in scripting like that you can double define a function but i am learning and trying how is that stupid...
If you sit here calling people morons they will give up and never learn |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 21 Dec 2014 04:22 PM |
No no no you connected an event. Where you made that function? That's defining. |
|
|
| Report Abuse |
|
|
|
| 21 Dec 2014 04:26 PM |
| ... knowing that is called an event and not a function does not help me understand how it works |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 21 Dec 2014 04:28 PM |
How about you google it so that you understand how it works. I'm annoyed because you somehow managed to leave somefunction as somefunction, and then question why it broke. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 21 Dec 2014 04:32 PM |
"scription"
lol
i will now use this term |
|
|
| Report Abuse |
|
|