Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/instances/Game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local Workspace = import("./Workspace")

local Game = BaseInstance:extend("DataModel")

function Game:init(instance)
function Game:init(instance, habitat)
AnalyticsService:new().Parent = instance
ContentProvider:new().Parent = instance
CoreGui:new().Parent = instance
Expand All @@ -40,6 +40,8 @@ function Game:init(instance)
UserInputService:new().Parent = instance
VirtualInputManager:new().Parent = instance
Workspace:new().Parent = instance

getmetatable(instance).instance.habitat = habitat
end

function Game.prototype:GetService(serviceName)
Expand Down
15 changes: 3 additions & 12 deletions lib/instances/LocalScript.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
--[[
Serves as just a source container right now.
Currently exactly the same as Script.
]]

local BaseInstance = import("./BaseInstance")
local InstanceProperty = import("../InstanceProperty")
local Script = import("./Script")

local LocalScript = BaseInstance:extend("LocalScript", {
creatable = true,
})

LocalScript.properties.Source = InstanceProperty.normal({
getDefault = function()
return ""
end,
})
local LocalScript = Script:extend("LocalScript")

return LocalScript
25 changes: 25 additions & 0 deletions lib/instances/Script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ local Script = BaseInstance:extend("Script", {
creatable = true,
})

function Script:init(instance)
local internal = getmetatable(instance).instance

internal.hasRun = false

instance.AncestryChanged:Connect(function()
if internal.hasRun then
return
end

local game = instance:FindFirstAncestorOfClass("DataModel")

if game == nil then
return
end

internal.hasRun = true

-- TODO: Correctly handle errors

local co = coroutine.create(loadstring(instance.Source))
getmetatable(game).instance.habitat.taskScheduler:schedule(0, co)
end)
end

Script.properties.Source = InstanceProperty.normal({
getDefault = function()
return ""
Expand Down