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

How Do I Make A Model That Spawn On A Certain Of Time?

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.

2 comments

0

Everything seems fine, I'd double check your hierarchies, it seems bricks may be the problem, any output? If Z is a model you will want to use a for loop to put all the bricks in workspace

0

I don't know, I'm trying to find the solution. D:

2 answers

✓ Accepted answer

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)

4 comments

0

Thanks :)

0

mark one of the answers as correct

0

do I put the script in the model or leave it in work space? And do I put it in a normal script or local script?

0

normal script and in workspace

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 :)

3 comments

0

You need an explanation though

1

I have an explanation in the script.

0

tru

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