Light system not working

I am new to scripting. The “if” part works fine. The “elseif” part is not working. There are no errors. Help would be appreciated! Thanks in advance!

Script:

local Light1 = game.Workspace.LightI.SpotLight
local Light2 = game.Workspace.LightII.SpotLight
local Light3 = game.Workspace.LightIII.SpotLight
local Light4 = game.Workspace.LightIIII.SpotLight
local DiscoScript = game.ServerScriptService.Disco
local DiscoBallOne = game.Workspace.DiscoBall1

if DiscoScript.Disabled == true then
	Light1.Enabled = false
	Light2.Enabled = false
	Light3.Enabled = false
	Light4.Enabled = false
	DiscoBallOne.Material = Enum.Material.Plastic

elseif DiscoScript.Disabled == false then
		Light1.Enabled = true
		Light2.Enabled = true
		Light3.Enabled = true
		Light4.Enabled = true
		DiscoBallOne.Material = Enum.Material.Glass
end

If the elseif part is not working then it means that the disco script is disabled. The elseif part will only run if the disco script is not disabled.

Exactly, I put a script in the Disco script so it prints something in the console when enabled. It is enabled for sure.

You didn’t print anything in the script.

Since you’re working with booleans, you can just use if/else.

if DiscoScript.Disabled then
	Light1.Enabled = false
	Light2.Enabled = false
	Light3.Enabled = false
	Light4.Enabled = false
	DiscoBallOne.Material = Enum.Material.Plastic
else -- Disabled == false
		Light1.Enabled = true
		Light2.Enabled = true
		Light3.Enabled = true
		Light4.Enabled = true
		DiscoBallOne.Material = Enum.Material.Glass
end
1 Like

Alright, thanks. I am always trying to make my code simpler.

This is triggered by multiple scripts. I have a GUI TextButton that enables the disco script. Inside the disco script, I made it print a message. It does that in the log and for some reason, that script does not work.

Weird thing is that the script only works if Disco script is enabled before. Meaning, it does not work with the click button. Yet, the click button enables it.

Since you are working between the client and the server, I’m going to ask, did you use a remote event?

No, I did not. Do I need to use it?

Yep for sure, your basically wanting to click the button from the client and then the server enables the discoscript for you so in order to do that you will need to use a remote event.

Oh, okay. What should I add to the script and all of that? I have not dealt with remote events before. I just started learning. :confused:

Oh right, no problem! I recommend you to read this page here: Client-Server Runtime | Documentation - Roblox Creator Hub

It talks about how the server and the client interact with each other. Since you are using a button, you will need to handle that button locally (on the client) and if you want the Discoscript to be enabled then the server will have to enable it. Anything related to the GUI or the player is only handled on the client, anything else is rather handled on the server.

If you read the page I gave you then you will understand what I’m trying to say, but yeah, if you are still struggling to understand that page you can watch this video: https://youtu.be/wCr5VXJ34T4

Man, thanks for the help! Have a good day!

1 Like

You are very welcome, if you think I solved your problem then be sure to hit that solution button so that everybody else will know that this topic has been solved! :smiley: