|
| 05 Jun 2013 10:50 AM |
owner = script.Parent.Parent.Parent.Name actualowner = game.Workspace:findFirstChild(owner) ownercar = actualowner.Car Light1 = ownercar.Lights.Light1 Light2 = ownercar.Lights.Light2 Light3 = ownercar.Lights.Light3 Light4 = ownercar.Lights.Light4
script.Parent.Button1Down:connect(function() if script.Parent.Text == ("Lights On") then script.Parent.Text = ("Lights off") Light1.PointLight.Enabled = true Light2.PointLight.Enabled = true Light3.PointLight.Enabled = true Light4.PointLight.Enabled = true end elseif
'elseif' is my problem. There's a red line under it, and I have no idea why its there. No, the script is not done.
swagmiester |
|
|
| Report Abuse |
|
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 05 Jun 2013 10:55 AM |
owner = script.Parent.Parent.Parent.Name actualowner = game.Workspace:findFirstChild(owner) ownercar = actualowner.Car Light1 = ownercar.Lights.Light1 Light2 = ownercar.Lights.Light2 Light3 = ownercar.Lights.Light3 Light4 = ownercar.Lights.Light4
script.Parent.Button1Down:connect(function()
if script.Parent.Text == ("Lights On") then script.Parent.Text = ("Lights off")
Light1.PointLight.Enabled = true Light2.PointLight.Enabled = true Light3.PointLight.Enabled = true Light4.PointLight.Enabled = true elseif --Elseif replaces the position of the end, you just use the end for the elseif statement.
|
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 11:01 AM |
Now that I did what I want, there's a red line under the last AFTER elseif.
owner = script.Parent.Parent.Parent.Name actualowner = game.Workspace:findFirstChild(owner) ownercar = actualowner.Car Light1 = ownercar.Lights.Light1 Light2 = ownercar.Lights.Light2 Light3 = ownercar.Lights.Light3 Light4 = ownercar.Lights.Light4
script.Parent.Button1Down:connect(function() if script.Parent.Text == ("Lights On") then script.Parent.Text = ("Lights off") Light1.PointLight.Enabled = true Light2.PointLight.Enabled = true Light3.PointLight.Enabled = true Light4.PointLight.Enabled = true elseif script.Parent.Text = ("Lights On") --(here) Light1.PointLight.Enabled = false Light2.PointLight.Enabled = false Light3.PointLight.Enabled = false Light4.PointLight.Enabled = false end end
swagmiester |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 05 Jun 2013 11:09 AM |
| script.Parent.Text = "Lights on" |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 11:16 AM |
Still a red line.
swagmiester |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 11:18 AM |
"elseif" requires another statement to test. It behaves just as "if", except it cannot be the introductory statement.
if (a) then elseif (b) then else end |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 11:25 AM |
owner = script.Parent.Parent.Parent.Name actualowner = game.Workspace:findFirstChild(owner) ownercar = actualowner.Car Light1 = ownercar.Lights.Light1 Light2 = ownercar.Lights.Light2 Light3 = ownercar.Lights.Light3 Light4 = ownercar.Lights.Light4
script.Parent.Button1Down:connect(function()
if script.Parent.Text == ("Lights On") then script.Parent.Text = ("Lights off")
Light1.PointLight.Enabled = true Light2.PointLight.Enabled = true Light3.PointLight.Enabled = true Light4.PointLight.Enabled = true
elseif script.Parent.Text == ("Lights On") --(here)
Light1.PointLight.Enabled = false Light2.PointLight.Enabled = false Light3.PointLight.Enabled = false Light4.PointLight.Enabled = false end
end |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 11:26 AM |
| Add a closing parenthesis to the last end. |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 11:31 AM |
[{[
if script.Parent.Text == ("Lights On") then script.Parent.Text = ("Lights off")
Light1.PointLight.Enabled = true Light2.PointLight.Enabled = true Light3.PointLight.Enabled = true Light4.PointLight.Enabled = true
elseif script.Parent.Text == ("Lights On") --(here)
]}]
You made the two test for the same thing. You made them both test if the Text was "Lights On". What's the point of that? They will counteract eachother, and your lights will always be on.
|
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 11:39 AM |
owner = script.Parent.Parent.Parent.Name actualowner = game.Workspace:findFirstChild(owner) ownercar = actualowner.Car Light1 = ownercar.Lights.Light1 Light2 = ownercar.Lights.Light2 Light3 = ownercar.Lights.Light3 Light4 = ownercar.Lights.Light4
script.Parent.Button1Down:connect(function() -- Turns The lights on if script.Parent.Text == "Lights On" then script.Parent.Text = "Lights off" Light1.PointLight.Enabled = true Light2.PointLight.Enabled = true Light3.PointLight.Enabled = true Light4.PointLight.Enabled = true elseif script.Parent.Text == "Lights Off" then Light1.PointLight.Enabled = false Light2.PointLight.Enabled = false Light3.PointLight.Enabled = false Light4.PointLight.Enabled = false end end) --ends the whole process.
No lines now.Thanks guys
swagmiester |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 11:47 AM |
Efficienizing it a bit:
owner = script.Parent.Parent.Parent.Name actualowner = game.Workspace:FindFirstChild(owner) ownercar = actualowner.Car Lights = {} for i = 1, 4 do table.insert(Lights, ownercar.Lights["Light"..i])
script.Parent.Button1Down:connect(function() if script.Parent.Text == "Lights On" then for _, v in pairs(Lights) do v.PointLight.Enabled = true end else for _, v in pairs(Lights) do v.PointLight.Enabled = false end end end) |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 12:11 PM |
How about: local owner = script.Parent.Parent.Parent.Name local actualowner = game.Workspace:findFirstChild(owner) local ownercar = actualowner.Car local Lights = { } for i = 1, 4 do table.insert(Lights, ownercar.Lights["Light"..tostring(i)]) end
script.Parent.Button1Down:connect(function() script.Parent.Text = script.Parent.Text == "Lights On" and "Lights Off" or "Lights On" for _, Light in pairs(Lights) do Light.Point.Light.Enabled = script.Parent.Text == "Lights On" and true or false end end) |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 12:13 PM |
Yeah, just made one like that myself, tweeted it to him before you submitted yours, though :P
owner, actualowner, ownercar = script.Parent.Parent.Parent.Name, game.Workspace:FindFirstChild(owner), actualowner.Car past Lights = {} for i = 1, 4 do table.insert(Lights, ownercar.Lights["Light"..i].PointLight) end
script.Parent.Button1Down:connect(function() for _, v in pairs(Lights) do v.PointLight.Enabled = (script.Parent.Text == "Lights On") and true or false end script.Parent.Text = (script.Parent.Text == "Lights On") and "Lights Off" or "Lights On" end) |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2013 12:30 PM |
Yours would be counter-acting again, though. It changes the text before lights, meaning it will change the lights based on the text already changed. When you were to click "Lights On", it would return itself to Lights Off, and then turn off the lights.
But other than that, brilliant! :)
Sorry, meant this for my last post; did v.PointLight, but Lights[#] is already .PointLight
owner, actualowner, ownercar = script.Parent.Parent.Parent.Name, game.Workspace:FindFirstChild(owner), actualowner.Car past Lights = {} for i = 1, 4 do table.insert(Lights, ownercar.Lights["Light"..i].PointLight) end
script.Parent.Button1Down:connect(function() for _, v in pairs(Lights) do v.Enabled = (script.Parent.Text == "Lights On") and true or false end script.Parent.Text = (script.Parent.Text == "Lights On") and "Lights Off" or "Lights On" end) |
|
|
| Report Abuse |
|
|