71 lines
2.8 KiB
Lua
71 lines
2.8 KiB
Lua
local mainStorage = game.ServerStorage.City
|
|
local main = script.Parent
|
|
local fowardEvent = mainStorage.FowardEvent
|
|
local backEvent = mainStorage.BackEvent
|
|
|
|
local foward = function(time)
|
|
local currentModel -- Gets the first model in mains
|
|
for _, child in pairs(main:GetChildren()) do -- children. Assumming everything else
|
|
if child:IsA("Model") then -- in the script goes right the
|
|
currentModel = child -- current model will be the only child
|
|
end -- that is a model.
|
|
end
|
|
local currentModelAge = tonumber(currentModel.Name) -- The currentModel's name is its age.
|
|
|
|
local nextModel = mainStorage:FindFirstChild(currentModelAge + time)
|
|
if nextModel ~= nil then
|
|
currentModel.Parent = mainStorage
|
|
nextModel.Parent = main
|
|
return
|
|
end
|
|
|
|
nextModel = currentModel:Clone()
|
|
local ageEvent = nextModel.AgeEvent
|
|
currentModel.Parent = mainStorage
|
|
nextModel.Name = currentModelAge + time
|
|
nextModel.Parent = main
|
|
|
|
print("Fired")
|
|
ageEvent:Fire(time)
|
|
end
|
|
fowardEvent.event:Connect(foward)
|
|
|
|
local back = function(time)
|
|
local currentModel -- Gets the first model in mains
|
|
for _, child in pairs(main:GetChildren()) do -- children. Assumming everything else
|
|
if child:IsA("Model") then -- in the script goes right the
|
|
currentModel = child -- current model will be the only child
|
|
end -- that is a model.
|
|
end
|
|
local currentModelAge = tonumber(currentModel.Name) -- The currentModel's name is its age.
|
|
|
|
local previousModel = mainStorage:FindFirstChild(currentModelAge - time) -- Checks to see if the model
|
|
if previousModel ~= nil then -- we want has already been
|
|
currentModel.Parent = mainStorage -- created. If it has
|
|
previousModel.Parent = main -- its parent is set to main
|
|
return -- the current one's to storage
|
|
end -- and the function is ended.
|
|
|
|
local storageModels = mainStorage:GetChildren() -- If we didnt find a model before
|
|
local timeDistance = 9999999999 -- we look though all the ones
|
|
for _, child in pairs(storageModels) do -- in storage and find the model
|
|
if child:IsA("Model") then -- with the shortest negetive time
|
|
local childAge = tonumber(child) -- to the target one
|
|
local difference = currentModelAge - time - childAge
|
|
if childAge > currentModelAge - time then
|
|
|
|
elseif difference < timeDistance then
|
|
timeDistance = difference
|
|
previousModel = child
|
|
end
|
|
end
|
|
end
|
|
|
|
previousModel = previousModel:Clone() -- Once we found a sutible model
|
|
currentModel.Parent = main -- we set its parents and store the old one
|
|
previousModel.Name = currentModelAge - time
|
|
previousModel.Parent = main
|
|
|
|
previousModel.AgeEvent:Fire(currentModelAge - time - tonumber(previousModel.Name)) -- Age the model to the ammount required to reach target
|
|
end
|
|
backEvent.event:Connect(back) |