How to set the transparency of a part when the clock time = 10?

So I have a game where I need a gate to close when the in game time = 10:00 and reopen when it equals 6:30.

Script:

local lighting = game:GetService("Lighting")

repeat

local Time = lighting:GetMinutesAfterMidnight()

if Time >= 1200 and Time < 390 then

script.Parent.Transparency = 0.5

elseif Time < 1200 and Time > 390 then

print("Ran2")

script.Parent.Transparency = 0

end

wait(1/15);

until script.Parent.Name ~= "Gate"

The thing is however that the script works it prints “Ran2” at the right times but it doesnt change the transparency of the part for some reason.

1 Like

Why not make it simpler like this?

local Lighting = game:GetService("Lighting")

function OpenCloseGate()
    if Lighting.ClockTime >= 10 then -- Close gate
        script.Parent.Transparency = 0.5
        script.Parent.CanCollide = true
    elseif Lighting.ClockTime <= 10 and Lighting.ClockTime > 6.3 then -- Open gate
        script.Parent.Transparency = 1
        script.Parent.CanCollide = false
    end
end

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(OpenCloseGate)

lots of edits in case you’re already incorporating this code

2 Likes

with this we still run into the same problem of it changing the first time but not the second time.

It should? The code I posted functions as expected.
https://gyazo.com/0748e241c6f373a4494150c8124146bc

1 Like

What is the parent of the script?

Im stupid I forgot to enable the script.

1 Like

I decided to make a quick day and night cycle and fuse it with the function I gave, which is in ServerScriptService. It references the part through workspace. Testing it within a part, it does the same.

EDIT: Ah, we all make some accidents some time. Especially me. Glad to see that it worked for you.