Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I control multiple models of SAME NAME with script?

Asked by 8 years ago

Hello everyone. I have a script t activate multiple emergency lights upon pressing a button. The problem is that only one turns on. It toggles the on and off, which I was surprised I could write in one try, but the other several lights (more will exist in the future) are not doing anything. Here is the directory:

[SCRIPT]>>Button>>Controls>>EmergencyLights<<Emergency Light(MULTIPLE)

Here is the script:

function onClicked() if script.Parent.Parent.Parent.EmergencyLight.Toggle.Value == true then script.Parent.Parent.Parent.EmergencyLight.Toggle.Value = false else script.Parent.Parent.Parent.EmergencyLight.Toggle.Value = true end end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

The script has three parents, the first is the part(button), the second is controls(Group of parts that make up a panel that controls other stuff), and the third is the main group, which contains the lights and controls. The object called "Toggle" is a true/false value that decides whether the light(s) is on. If anyone knows how to tell my script to toggle all of the lights please tell me!

  • PJB
0
I really wish that this website recognized the line breaks... PhilipJonnyBob12 5 — 8y
0
It does. Use code blocks.  Edit your post to use a code block. BlueTaslem 18071 — 8y
0
If you want breaks between other text, use a double line break in the text area. This is standard markdown format. BlueTaslem 18071 — 8y

1 answer

Log in to vote
0
Answered by
Edenojack 171
8 years ago
function onClicked() 
if script.Parent.Parent.Parent.EmergencyLight.Toggle.Value == true then script.Parent.Parent.Parent.EmergencyLight.Toggle.Value = false 
else
script.Parent.Parent.Parent.EmergencyLight.Toggle.Value = true 
end 
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

to turn them all on:

Local LightModel = script.Parent.Parent.Parent
function onClicked() 
if script.Parent.Parent.Parent.EmergencyLight.Toggle.Value == true then 
for k,v in pairs(LightModel:GetChildren()) do
v.Toggle.Value = false
end
else
for k,v in pairs(LightModel:GetChildren()) do
v.Toggle.Value = true
end
end 
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

should be right, but you might want to change the paths. Essentially, it iterates through the model's parts and changes the value you want.

0
Thank you, but now none are turning on. I'll try to change the paths PhilipJonnyBob12 5 — 8y
0
Okay I got it to work. the "Local" at the very top needed to have the L lowercased... LOL but yeah now they all turn on you are genius PhilipJonnyBob12 5 — 8y
0
Whatever you are defining "On" as, either a light being enabled or a material changing to Neon, that what needs to be in place of v.Toggle.Value = true Edenojack 171 — 8y
0
Ey! No probs m80 :) Edenojack 171 — 8y
Ad

Answer this question