Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Light script not functioning anymore?

Asked by 8 years ago

Hello, I need help with this script that wont work any more

local light = script.Parent
local lightlight = light.SpotLight
local lv = game.ServerStorage.lightvalue.Value

while true do
wait(.1)    
    if lv == true then
        lightlight = false
    elseif lv == false then
        lightlight.Enabled = true
    end
end

i have another script changing light value and storing it in game.serverstorage.lightvalue.Value (light value is a boolean) Thanks

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago
Edited 8 years ago

The problem with your code is where you're defining the 'lv' variable, as well as line 8.

Lets talk about while loops. They repeat any code inside the scope of the loop until the given condition is false. So, if your code has repeated waiting a decisecondยน and checking the 'lv' variable, eventually the variable will not be up to date with the actual value.

You have cached the 'lv' variable to hold the value of lightvalue at the moment that the script reads line 3.

To allow your script to have live feed of the lightvalue's value, you need to define the 'lv' variable inside the while loop.

Line 8: lightlight.Enabled = false; You should have indexed the 'Enabled' property

local light = script.Parent:WaitForChild("SpotLight");

while wait(.1)   do  
    local lv = game.ServerStorage.lightvalue.Value
    lightlight.Enabled = lv
end
Ad

Answer this question