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

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

Asked by 5 years ago

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

Log in to vote
0
Answered by
valchip 789 Moderation Voter
5 years ago
Edited 5 years ago
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.

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 1NSAN1TY11 0 — 5y
0
Also, does the type of script matter, and where it's placed? I used a regular script and placed it in Workspace 1NSAN1TY11 0 — 5y
0
Sorry for confusing you, I thought `ClockTime` was an int/number value in the Lighting. I editted the answer, check it out. valchip 789 — 5y
0
Use While true do for infinite loops.. mixgingengerina10 223 — 5y
View all comments (4 more)
0
^ I added a wait() so it wouldn't crash, it is still an infinite loop, are you dumb? valchip 789 — 5y
0
If your doing 'if' you must put two equals, or it will not work, eg: Starnamics 24 — 5y
0
ew wait() as a condition. Don't ever do that!!! User#19524 175 — 5y
0
No I wanna use wait(). valchip 789 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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)
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? 1NSAN1TY11 0 — 5y
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. User#19524 175 — 5y

Answer this question