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
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'.
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)
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)