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

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

Asked by
ImfaoXD 158
8 years ago

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.

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 dragonkeeper467 453 — 8y
0
I don't know, I'm trying to find the solution. D: ImfaoXD 158 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

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)

0
Thanks :) ImfaoXD 158 — 8y
0
mark one of the answers as correct dragonkeeper467 453 — 8y
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? ImfaoXD 158 — 8y
0
normal script and in workspace dragonkeeper467 453 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
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 :)

0
You need an explanation though dragonkeeper467 453 — 8y
1
I have an explanation in the script. TheDeadlyPanther 2460 — 8y
0
tru dragonkeeper467 453 — 8y

Answer this question