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: Hit a dead end. Don't know what to do.

Previous Thread :: Next Thread 
cpbuilderman is not online. cpbuilderman
Joined: 10 Sep 2010
Total Posts: 2586
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 is not online. 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
cpbuilderman is not online. cpbuilderman
Joined: 10 Sep 2010
Total Posts: 2586
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 is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
05 Jun 2013 11:09 AM
script.Parent.Text = "Lights on"
Report Abuse
cpbuilderman is not online. cpbuilderman
Joined: 10 Sep 2010
Total Posts: 2586
05 Jun 2013 11:16 AM
Still a red line.

swagmiester
Report Abuse
Ravenshield is not online. Ravenshield
Joined: 21 Nov 2007
Total Posts: 4143
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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
05 Jun 2013 11:26 AM
Add a closing parenthesis to the last end.
Report Abuse
Ravenshield is not online. Ravenshield
Joined: 21 Nov 2007
Total Posts: 4143
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
cpbuilderman is not online. cpbuilderman
Joined: 10 Sep 2010
Total Posts: 2586
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
Ravenshield is not online. Ravenshield
Joined: 21 Nov 2007
Total Posts: 4143
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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
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
Ravenshield is not online. Ravenshield
Joined: 21 Nov 2007
Total Posts: 4143
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
Ravenshield is not online. Ravenshield
Joined: 21 Nov 2007
Total Posts: 4143
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
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