Currently im working on trying to get PointLights and SpotLights to change brightness. The problem is (at the spot I pointed out) that the brightness doesnt even change but then again the noise plays. So why on earth is the brightness not changing? And they are spotlights and pointlights so thats not the problem.
local FIred = game.ReplicatedStorage.Jumpscare1
local debounce = false
FIred.OnClientEvent:Connect(function()
if debounce == false then
for i,v in pairs (workspace.Train1.Model:GetDescendants()) do
if v:IsA("Part") or v:IsA("Decal") then
v.Transparency = 0
script.Parent.Scream:Play()
end
end
wait(2)
------------------------------------------------------------------------------------------------------- Not working
for i,v in pairs (workspace.Train1:GetDescendants()) do
if v:IsA("SpotLight") or v:IsA("PointLight") then
v.Brightness = 0
game.StarterGui.Electricity_surge:Play()
wait(5)
workspace.Train1.Model:Destroy()
wait(0.05)
game.StarterGui.Electricity_Up:Play()
v.Brightness = 5
-------------------------------------------------------------------------------------------------------
end
end
end
end)
Seems like you’re checking 2 different lights at the same line, which is incorrect. If the script finds a SpotLight, it’ll only change the brightness of that, and the pointlight is left to nowhere. You’d want to create 2 if statements separately - so one for pointlight, and one for spotlight.
for i,v in pairs (workspace.Train1:GetDescendants()) do
if v:IsA("SpotLight") then
if v:IsA("PointLight") then
v.Brightness = 0
game.StarterGui.Electricity_surge:Play()
wait(5)
workspace.Train1.Model:Destroy()
wait(0.05)
game.StarterGui.Electricity_Up:Play()
v.Brightness = 5
end
end
end
I believe you are saying something more like this. Am I correct?
if v:IsA("SpotLight") then
v.Brightness = 0
game.StarterGui.Electricity_surge:Play()
wait(5)
workspace.Train1.Model:Destroy()
wait(0.05)
game.StarterGui.Electricity_Up:Play()
v.Brightness = 5
end
if v:IsA("PointLight") then
v.Brightness = 0
game.StarterGui.Electricity_surge:Play()
wait(5)
workspace.Train1.Model:Destroy()
wait(0.05)
game.StarterGui.Electricity_Up:Play()
v.Brightness = 5
end
The code you written would check the SpotLight then if that SpotLight is the PointLight, which will do nothing.
I cant really have this happen because it would play the same thing two times… and at seperate moments in time… sorry but I cant really let this happen
Then I’m assuming that it’s not possible to have 2 of them at once, as you need to check the v individually instead of running an if function for both.
Edit: However, you can change the name of the pointlight/spotlight to a specific name then check if they have that name, or insert it into a table. @Nistrict
Oh, just realised and tested it out - guess I was wrong in that part. I’m guessing that you’d need to change the game.StarterGui to player.PlayerGui instead. If that doesn’t work, can you debug it by using print and see where it stops the code at?
for i,v in pairs (workspace.Train1:GetDescendants()) do
if v:IsA("SpotLight") then
v.Brightness = 0
print("lighting changed")
game.StarterGui.Electricity_surge:Play()
wait(5)
workspace.Train1.Model:Destroy()
wait(0.05)
game.StarterGui.Electricity_Up:Play()
v.Brightness = 5
end
end
It printed, didnt change the brightness, now what the heck is going on.
Okay, I just tested the script and it seems to work fine (without the StarterGui things). What I can suggest you is to change workspace to game.Workspace (since I used it, but I’m unsure if it’ll change anything), change the StarterGui to the PlayerGui. The script was tested on the server rather than the client.
Edit: it works on the client as intended too. I’m sure it’s the StarterGui that’s causing the issue.
It should work on the client side. Make sure startergui is replaced with something along the lines of game.Players.LocalPlayer.PlayerGui.
Also, you destroy the train, and then try to change properties of a child of the train that should no longer exist?
for i,v in pairs (workspace.Train1:GetDescendants()) do
if v:IsA("SpotLight") then
v.Enabled = false
wait(5)
v.Enabled = true
end
end
Sadly had to get rid of the sounds and cut it down a lot. Still doesnt look like it changed anything because when I look at the enabled property nothing changed. @BanTech
If the effect you want is to have them all turn off at once rather than what I showed, this works:
local function lights(value)
for i,v in pairs(game.Workspace.Train1:GetDescendants()) do
if v:IsA("SpotLight") then
v.Enabled = value
end
end
end
lights(false)
wait(5)
lights(true)
Probably not the best way to do it idk, but it works.
Sorry I couldnt respond soon enough but, I made a video on the problem when you see the jumpscare thing. The lights never changed, but then look in the output. bandicam 2020-08-16 07-14-47-385.mp4 - Google Drive