|
| 21 Feb 2014 08:30 PM |
I am making a junction track and Im editing a click door script to make it work. I need to know how to make the script to effect all bricks instead of one. All the bricks used to make the curve part is named "Rail".
function on() isOn = true script.Parent.Transparency = 0 script.Parent.Parent.Parent.Thingy.Rail.Transparency = 1 script.Parent.CanCollide = true script.Parent.Parent.Parent.Thingy.Rail.CanCollide = false end
function off() isOn = false script.Parent.Transparency = .5 script.Parent.Parent.Parent.Thingy.Rail.Transparency = 0 script.Parent.CanCollide = false script.Parent.Parent.Parent.Thingy.Rail.CanCollide = true end
Problem is it only changed one brick in the curve. I cant induvidually name all of them "RailA", "RailB", etc. and it would be too much in the script. I am a newb to LUA and I think there is comething like "Children" for this. |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Feb 2014 08:38 PM |
local PartsToAffect = script.Parent.Parent.Parent.Thingy:GetChildren() for x = 1, #PartsToAffect do if PartsToAffect[x].Name == "" then--Change the name of all the parts you want affected to the same thing and place that name here --Function Here end end |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Feb 2014 08:42 PM |
This might work.
function on() up1 = script.Parent:GetChildren() up2 = script.Parent.Parent:GetChildren() up3 = script.Parent.Parent.Parent:GetChildren() for i=1,#up1 do if up1[i].ClassName == "Part" or "WedgePart" then up1[i].Transparency = 1 up1[i].CanCollide = true end end for i=1,#up2 do if up2[i].ClassName == "Part" or "WedgePart" then up2[i].Transparency = 1 up2[i].CanCollide = true end end for i=1,#up3 do if up3[i].ClassName == "Part" or "WedgePart" then up3[i].CanCollide = false up3[i].Transparency = 1 end end end
function off() isOn = false up1 = script.Parent:GetChildren() up2 = script.Parent.Parent:GetChildren() up3 = script.Parent.Parent.Parent:GetChildren() for i=1,#up1 do if up1[i].ClassName == "Part" or "WedgePart" then up1[i].Transparency = .5 up1[i].CanCollide = false end end for i=1,#up2 do if up2[i].ClassName == "Part" or "WedgePart" then up2[i].Transparency = 0 up2[i].CanCollide = true end end for i=1,#up3 do if up3[i].ClassName == "Part" or "WedgePart" then up3[i].CanCollide = true up3[i].Transparency = 0 end end end |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 08:42 PM |
| Wait by function here do you mean by the function for the curved part or all of it. |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 08:43 PM |
| And what is the "Part" or "WedgePart" |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 08:44 PM |
| I want it simple, sorry for triple post. |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Feb 2014 08:51 PM |
| Everyone is aware of this thread. Stop bumping. |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 08:54 PM |
| sonic I gave you a very effective function. As long as the parts in question are all named the same thing and placed in the same path it will work. |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 08:56 PM |
Yes I know, but then what do I do to this part: script.Parent.Transparency = 0 script.Parent.CanCollide = true |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 08:59 PM |
Double post, sorry. How are you supposed to add it? This is what I just did: local PartsToAffect = script.Parent.Parent.Parent.Thingy:GetChildren() for x = 1, #PartsToAffect do if PartsToAffect[x].Name == "Rail" thenthing and place that name here function on() isOn = true script.Parent.Transparency = 0 script.Parent.CanCollide = true end end end
It said "function here". Like I said, I"m a newb to scripting. |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 09:00 PM |
Switch = --Place the path of the value here that will determine on/off Thingy = script.Parent.Parent.Parent.Thingy
Switch.Changed:connect(function() if Switch.Value == true then local Rails = Thingy:GetChildren() for x = 1, #Rails do if Rails[x].Name == "Rail" then Rails[x].Transparency = 1 Rails[x].CanCollide = false end end script.Parent.CanCollide = true else local Rails = Thingy:GetChildren() for x = 1, #Rails do if Rails[x].Name == "Rail" then Rails[x].Transparency = 0 Rails[x].CanCollide = true end end script.Parent.CanCollide = false end end) |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 09:02 PM |
| Sorry, but do I replace the entire script with that? |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 09:04 PM |
I just wrote this from scratch under the assumption you are using a BoolValue as a switch to turn it on and off. Short answer yes this is a full script.
However, I do not know the hierarchy on which the railing is built, therefore you may need to edit the pathing. |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 09:09 PM |
I think I got this... thanks if it works. Incase it doesn't, I have a model that contains the straight, which contains 3 bricks, 2 rails and a rail that is used in the switch. In the model it has "Thingy" which is a part of the curve grouped seperatly so the switching mechanisim only affects that area. And last I have the curve, same like the stragiht but doesnt have any special things. |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 09:11 PM |
| I just need a onclick so if I click a lever it will change the BoolValue, which I placed inside of the part in the straight used for the junction. |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Feb 2014 09:29 PM |
| I already told you that you may have to edit the script to fit the hierarchy of your railing. |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 09:31 PM |
It fits but the clicking and the boolvalue doesnt. I have the model for someone to take a look at. http://www.roblox.com/My-Track-Junction-Left-item?id=147216432 |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 09:45 PM |
it doesnt work when you click because it doesnt activate upon clicking. it only activates when the BoolValue changes.
In order to activate it upon clicking you must create a connection between the MouseDetector and the BoolValue
MouseDetector.MouseClick:connect(function() if Switch.Value == true then Switch.Value = false else Switch.Value = true end end)
Again, you'll need to edit this to fit the pathing of the MouseDetector and the BoolValue |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2014 09:46 PM |
| Plus nobody can take the model unless it's public lol |
|
|
| Report Abuse |
|
|
| |
|
| |
|