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

How to use TimeOfDay?

Asked by
novipak 70
9 years ago

So, for my game I am teleporting all of the players into a certain area of my map.

In a separate script I have the time changing.

Here is my code:

local target = CFrame.new(207.73, 1.5, 4065.287)
local tod = game.Lighting.TimeOfDay
game.Lighting.Changed:connect(function(TimeOfDay)
    if tod == "00:03:20" then
        print("Time if passed.")
        for i, player in ipairs(game.Players:GetChildren()) do
            if player.Character and player.Character:FindFirstChild("Torso") then
                print("char check and torso check passed.")
                player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
           end
        end
    end
end)

So, am I just using time of day wrong? I'm thinking the if statement isn't working but I'm not sure how to fix it.

Oh and, there are also no errors

2 answers

Log in to vote
3
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your Problem

When you define tod on line 2 then the value becomes static, meaning it will never change unless manually changed. If you want the value to change then don't index TimeOfDay when defining 'tod', but index it when checking 'tod'.


Code

local target = CFrame.new(207.73, 1.5, 4065.287)
local tod = game.Lighting

game.Lighting.Changed:connect(function(TimeOfDay)
    if tod.TimeOfDay == "00:03:20" then
        print("Time if passed.")
        for i, player in ipairs(game.Players:GetChildren()) do
            if player.Character and player.Character:FindFirstChild("Torso") then
                print("char check and torso check passed.")
                player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
            end
        end
    end
end)
0
Thanks dude! With a few changes, this has ended up working perfectly. novipak 70 — 9y
Ad
Log in to vote
4
Answered by 9 years ago

You should not set a variable to a value of an object. You should use the .Changed function on the object and then check if its value is different.

local target = CFrame.new(207.73, 1.5, 4065.287)
local lighting = game.Lighting

lighting.Changed:connect(function()
    if lighting.TimeOfDay == "00:03:20" then
        for i,v in next,game.Players:GetChildren() do
            v.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
        end
    end
end)

Answer this question