I can't figured it out how to make this script works. I'm trying to make the model that is in lighting and spawn onto the map on a certain of time like for example; when it turn night time, the model will appear on the map. How can I do that?
Here is the link to the model so you could have a better of understanding:
http://www.roblox.com/unnamed-item?id=313479870
local Time = game.Lighting local Bricks = game.Lighting.Z Time.Changed:connect(function() if Time.TimeOfDay == "14:00:00" then Bricks.Parent = game.Workspace end end)
Thank You.
Alright I figured out whats wrong, and I tested it myself :). I used a coroutine to cycle through time below, so dont worry about that if you dont understand it, yet a good skill to learn! Your script is perfectly fine, i think the issue is with the script changing the time, take notice of GetMinutesAfterMidnight() and SetMinutesAfterMidnight(). If your other script is working fine the script you have above should work!
***I would store models in serverstorage, not game.Lighting, but up to you, either will work fine
local Time = game.Lighting local Bricks = game.Lighting.Z -- Model location Time.Changed:connect(function() if Time.TimeOfDay == "14:00:00" then print("Time of day acquired!") Bricks.Parent = game.Workspace --Insert model end end) --coroutine stuff to cycle through time function ChangeTime() while wait(.1) do game.Lighting:SetMinutesAfterMidnight(game.Lighting:GetMinutesAfterMidnight() + 1) end end changetime = coroutine.create(ChangeTime) coroutine.resume(changetime)
local time = game.Lighting local model = game.Lighting.ModelName:Clone() local name = game.Lighting.ModelName.Name -- name of the model local timeToSpawn = 18 -- when to clone model local timeToRemove = 06 -- when to remove model time.Changed:connect(function(property) local t = time.TimeOfDay:sub(1,2) -- gets the hour local num = tonumber(t) -- makes the string a number if num then -- if it can be converted to a number if num == timeToSpawn then -- if the time is right if not game.Workspace:FindFirstChild(name) then -- makes sure there isn't the model in workspace model.Parent = game.Workspace -- clones it end elseif num == timeToRemove then if game.Workspace:FindFirstChild(name) then -- checks to see if the model is in workspace game.Workspace[name]:remove() -- removes the model end end end end
Hope I helped :)