Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Whenever I try to assign a value to ClockTime it says its invalid. Help?

Hey there! Recently, I've started working on an rpg style game, and I'm having a hard time with ClockTime. Honestly, I'm a terrible scripter so I have no idea what I did wrong. I had put a Day/Night cycle script in, and started working on this script, which is supposed to make a Gate invisible in the daytime, and visible in night. My problem though, is that whenever I try to assign the ClockTime value, it says it's invalid and won't work when I test it. It's at the 'if ClockTime = 6 then' part. Sorry if this is really obvious, but like I said earlier Im kind of a garbage script so I don't really know what I did wrong.

local ClockTime = game.Lighting.ClockTime

if ClockTime = 6 then
	game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 1
	game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = true
	game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 1
	game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = true
end

if ClockTime = 18 then 
	game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 0
	game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = false
	game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 0
	game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = false
end

2 answers

local ClockTime = game.Lighting.ClockTime

while wait() do

ClockTime = game.Lighting.ClockTime

if ClockTime == 6 then
    game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 1
    game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = true
    game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 1
    game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = true
end
	 
if ClockTime == 18 then
    game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 0
    game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = false
    game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 0
    game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = false
end
end

I think that should work.

8 comments

0

I guess I'm sort of confused. ClockTime.Value? I thought ClockTime was it's own value. Like Transparency for example. When you want to change the value of transparency you just type game.Workspace.Part.Transparency = 1

0

Also, does the type of script matter, and where it's placed? I used a regular script and placed it in Workspace

0

Sorry for confusing you, I thought ClockTime was an int/number value in the Lighting. I editted the answer, check it out.

0

Use While true do for infinite loops..

0

^ I added a wait() so it wouldn't crash, it is still an infinite loop, are you dumb?

0

If your doing 'if' you must put two equals, or it will not work, eg:

0

ew wait() as a condition. Don't ever do that!!!

0

No I wanna use wait().

###Problem is, you're trying to check something with an if statement, but incorrectly. The assignment operator = is exclusively for assignment. The comparison operator is ==. You should also be using SetMinutesAfterMidnight and GetMinutesAfterMidnight.

###Look at the first line:

local ClockTime = game.Lighting.ClockTime

###That variable does NOT hold a reference to the property, and if the ClockTime changes, the variable will not update either. Use a Changed event to check if it changes.

local Lighting = game:GetService('Lighting')

Lighting:GetPropertyChangedSignal('ClockTime'):Connect(function()
    if Lighting:GetMinutesAfterMidnight() == 6*60 then -- if the time is 6:00am
        game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 1
        game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = true
        game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 1
        game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = true

    elseif Lighting:GetMinutesAfterMidnight() == 18*60 then -- if time is 6:00pm

        game.Workspace.StarterTownEntrance.Gate_Metal.Transparency = 0
        game.Workspace.StarterTownEntrance.Gate_Metal.CanCollide = false
        game.Workspace.StarterTownEntrance.Gate_Wood.Transparency = 0
        game.Workspace.StarterTownEntrance.Gate_Wood.CanCollide = false
    end
end)

2 comments

0

Could you please define what you mean by a Changed event? I'm a scrub scripter so I dunno what that is or what that means. Like, is it a regular event thats been re-named, and placed somewhere else or?

0

Changed is an event that fires each time some property changes. I used GetPropertyChangedSignal on the ClockTime property to run code only when that property changes. Much better than having a loop run ever 0.02 seconds or so.

This discussion is preserved as it was. New answers, comments, and votes are closed.