Issue with PointLight Brightness

Does anyone know what is the issue, when I click the button on UI it won’t change brightness of the PointLight in workspace. I’ve tried it in server script and in local script.

https://gyazo.com/5511c262becb1d6f656b1e5a81055ecf

I have tried looking on DevHub but I haven’t find anything new.

Note: Code below is in a local script.

local MainFrame = script.Parent
local PlayClapMusicButton = MainFrame.Clap
local CloseCurtainsButton = MainFrame.Close_Curtains
local OpenCurtainsButton = MainFrame.Open_Curtains
local PlayEndingMusicButton = MainFrame.Ending_Music
local ExitButton = MainFrame.Exit
local PlayIntermissionMusic = MainFrame.Intermission
local LightsOnButton = MainFrame.Lights_On
local LightsOffButton = MainFrame.Lights_Off
local CinemaAudio = game.Workspace.cinemaarea
local StageLight = game.Workspace.stagelight.PointLight

local LightsOn = false
local CurtainsOpen = false

function TurnLightsOn()
	while wait(0.1) do 
		StageLight.Brightness = StageLight.Brightness + 0.1
		if StageLight.Brightness == 3 then
			break
		end
	end
end

function TurnLightsOff()
	while wait(0.1) do 
		StageLight.Brightness = StageLight.Brightness - 0.1
		if StageLight.Brightness == 0 then
			break
		end
	end
end

PlayClapMusicButton.MouseButton1Click:Connect(function()
	CinemaAudio.SoundId = ""
	CinemaAudio:Play()
end)

PlayIntermissionMusic.MouseButton1Click:Connect(function()
	CinemaAudio.SoundId = ""
	CinemaAudio:Play()
end)

PlayEndingMusicButton.MouseButton1Click:Connect(function()
	CinemaAudio.SoundId = ""
	CinemaAudio:Play()
end)

ExitButton.MouseButton1Click:Connect(function()
	MainFrame:Destroy()
end)

LightsOnButton.MouseButton1Click:Connect(function()
	TurnLightsOn()
end)

LightsOffButton.MouseButton1Click:Connect(function()
	TurnLightsOff()
end)

If you have a solution or an idea I would love to hear it.

1 Like

i am a bit confused on how that would work.
I have never seen someone do that so i don’t know if it is a normal thing but i just have no idea how that would work

What do you exactly mean by that? Should wait be inside the loop? Like this;

while true do
wait(0.1)
end

when you do while you need to give it a true statement for it to loop so if you pass in something that is false or nil it won’t loop so doing wait(0.1) there would give it a nil so it wouldn’t do anything

Have you tried using debounce or toggle variable?

--Similar to this:
local isOpen = false

local function OpenLights()
    if isOpen == false then
         isOpen = true

        Lightbulb.PointLight.Enable = true
    end
end

local function OpenLights()
    if isOpen == true then
         isOpen = false

        Lightbulb.PointLight.Enable = true
    end
end

1 Like

In this case for me, I’d rather use TweenService for better fade effect

1 Like

Yes, that was exactly what I was trying to do but I don’t know how that Tween would work, could you show me an example?

also i would recommend if you did

while StageLight.Brightness > 0 do
      -- also when dealing with while loops always remember to add a wait() in it or the game will crash
      -- decrease brightness
end
1 Like

Sure, I’ll try it. Thanks for letting me know.

local TweenService = game:GetService("TweenService")

local FadeInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)


local isOpen = false
local function OpenLights()
    if isOpen == false then
        TweenService:Create(Lightbulb.PointLight, FadeInfo, {Brightness = 3}):Play()
        isOpen = true
    end
end

local function CloseLights()
    if isOpen == true then
        TweenService:Create(Lightbulb.PointLight, FadeInfo, {Brightness = 1}):Play()
        isOpen = false
    end
end

Edit: I forgot to add Interval for the TweenInfo

--I added a 1 in the TweenInfo.new(1, ~~~)
2 Likes

Should I implement RemoteEvent or would I put this in local or server script?

1 Like

If you are going to show the fade of the light in all players use Remote events but if not use my recommended script

2 Likes

Yeah, I’m trying so everyone can see it cause it’s for a theatre.

2 Likes

here slowly makes it brighter and brighter and brighter probably “if StageLight.Brightness == 3 then” this area is not working
edit : it makes it stop in 3 but probably it needs to be changed or script’s that stage is not working

2 Likes