I’m trying to make an InGameEvent system for my game purely based and designed off Lighting.ClockTime
. There is a bunch of issues I have ran into while testing and creating it. Some included The spawning system not always running, Flashing model when its not suppose to be sent. Currently I have ran into an issue where the models will not destroy itself until ALL models have reached their despawn time which isnt suppose to happen at all.
The goal I am looking for is where when the clocktime >= spawn time the model fades in and spawns (Which seems like I have made work so far. But can also just not work sometimes). Once the clocktime >= despawn time the model fades out and destorys itself (This doesn’t always work.)
InGameEventLib
local InGameEventsLib = {
--Format: {"ModelName": Model, SpawningTime: number, Duration: number}
-- REFER TO CLOCKTIME!
{"Treehouse", 10, 15},
{"Treehouse2", 15, 23.99}
}
return InGameEventsLib
Main
--> Services
local Lighting = game:GetService("Lighting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
--> References
local InGameEvents = ReplicatedStorage.InGameEvents
--> Modules
local InGameEventsLib = require(ReplicatedStorage.Modules.Library.InGameEventsLib)
local TweenManager = require(ReplicatedStorage.Modules.TweenManager)
function UpdateTime()
local ClockTime = Lighting.ClockTime
local Interval = 0.01
Lighting.ClockTime = ClockTime + Interval
end
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
for _, TimeInfo in InGameEventsLib do
local InGameModel: Model = InGameEvents:FindFirstChild(TimeInfo[1]):Clone()
local SpawnTime: Number = TimeInfo[2]
local DespawnTime: NumberValue = TimeInfo[3]
-- Pre-set values for spawning (Tween)
for _, Parts in InGameModel:GetDescendants() do
if Parts:IsA("Part") or Parts:IsA("MeshPart") or Parts:IsA("UnionOperation") or Parts:IsA("BasePart") then
Parts.Transparency = 1
end
end
if (Lighting.ClockTime >= SpawnTime and not workspace:FindFirstChild(TimeInfo[1])) then
InGameModel:AddTag("InGameEvent")
for _, Parts in InGameModel:GetDescendants() do
if Parts:IsA("Part") or Parts:IsA("MeshPart") or Parts:IsA("UnionOperation") or Parts:IsA("BasePart") then
TweenManager:Play(Parts, {3, "Sine", "Out"}, {Transparency = 0})
end
end
InGameModel.Parent = workspace
elseif (Lighting.ClockTime >= DespawnTime and workspace:FindFirstChild(TimeInfo[1]) and workspace:FindFirstChild(TimeInfo[1]):HasTag("InGameEvent")) then
local EventModel: Model = workspace:FindFirstChild(TimeInfo[1])
if EventModel:HasTag("InGameEvent") then
for _, Parts in EventModel:GetDescendants() do
if Parts:IsA("Part") or Parts:IsA("MeshPart") or Parts:IsA("UnionOperation") or Parts:IsA("BasePart") then
TweenManager:Play(Parts, {1, "Sine", "Out"}, {Transparency = 1})
end
end
end
task.wait(3)
EventModel:Destroy()
end
end
end)
RunService.Heartbeat:Connect(UpdateTime)
TweenManager
--> Services
local TweenService = game:GetService("TweenService")
--> Tables
local Tween = {}
local function GetTweenInfo(tweenInfo)
if typeof(tweenInfo) == "table" then
if tweenInfo[2] and typeof(tweenInfo[2]) == "string" then
tweenInfo[2] = Enum.EasingStyle[tweenInfo[2]]
end
if tweenInfo[3] and typeof(tweenInfo[3]) == "string" then
tweenInfo[3] = Enum.EasingDirection[tweenInfo[3]]
end
tweenInfo = TweenInfo.new(unpack(tweenInfo))
end
return tweenInfo
end
function Tween:Create(Instance: Instance, tweenInfo, Properties)
return TweenService:Create(Instance, GetTweenInfo(tweenInfo), Properties)
end
function Tween:Play(Instance: Instance, tweenInfo, Properties)
local Tween = Tween:Create(Instance, tweenInfo, Properties)
Tween:Play()
return Tween
end
return Tween