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

What is wrong with my SpotLight script?

Asked by 9 years ago

So... after I added a day/night cycle script to my game, I made a light column with SpotLight. Then I added a script to the SpotLight to make it opens at a specific time(19:00:00) and closes at(5:00:00). The script is not working, here is it:-

game.Lighting.Changed:connect(function()
    local myTime = game.Lighting.TimeOfDay
    if myTime == "19:00:00" then
        SpotLight.enabled = true
    else if myTime == "5:00:00" then
        SpotLight.enabled = false
    end
end

And here is the day/night cycle script if you think there's something wrong in it, note that I don't have troubles with this script:-

local dayLength = 24

local cycleTime = dayLength*60
local minutesInADay = 24*60

local lighting = game:GetService("Lighting")

local startTime = tick() - (lighting:getMinutesAfterMidnight() / minutesInADay)*cycleTime
local endTime = startTime + cycleTime

local timeRatio = minutesInADay / cycleTime

if dayLength == 0 then
    dayLength = 1
end

repeat
    local currentTime = tick()

    if currentTime > endTime then
        startTime = endTime
        endTime = startTime + cycleTime
    end

    lighting:setMinutesAfterMidnight((currentTime - startTime)*timeRatio)
    wait(1/15)
until false

NOTE: Please tell in your answer the following:-

1.Shall I put this script in normal script or in local script?

2.Shall I put this script in the SpotLight itself or in the part which has the SpotLight in.

3.Explain what did you change.

Thanks for helping.

1 answer

Log in to vote
0
Answered by 9 years ago

Try removing the local prior to your variable in the spotlight script. A variable is a variable, the local could be messing you up. It SHOULD work after that.

0
Can you please explain more, or write an example of a code because I am new to scripting. kudorey619 138 — 9y
Ad

Answer this question