This has confused me for the longest time. Roblox has functions in functions. Like for example:
game.Players:CreateLocalPlayer():Clone():GetPropertyChangedSignal("Name"):Connect(function())
Like I’m sorry, what? I see some modules kind of do something like this like DataStore2.
local DataStore2 = require(game.ServerScriptService.DataStore2)
DataStore2.Combine("DATA", "Saves")
DataStore2("Saves", game.Players.Warriorfoox):Get(nil)
I was wondering how it would be possible to do something like this, as I’ve tried multiple things and I just can’t figure this out. Here’s an example of what I tried, I know the use of this would be nothing, but it’s just me attempting this.
local Properties = {}
local function Tween(instance, info, data)
game:GetService("TweenService"):Create(instance, info, data):Play()
end
function Properties:SetColor(NewColor, TweenData)
if self.instance.Color then
if TweenData ~= nil then
Tween(self.instance, TweenData, {Color = NewColor})
else
self.instance.Color = NewColor
end
end
end
local PropertiesMetatable = {}
PropertiesMetatable.__index = Properties
local Instances = {}
function Instances:CreatePart(Name, Parent)
local Part = Instance.new("Part")
Part.Name = Name
if Parent == nil then
Parent = workspace
end
Part.Parent = Parent
local NewInstance = {}
NewInstance.instance = Part
setmetatable(NewInstance, PropertiesMetatable)
return NewInstance
end
return Instances
The usage of this that I’m trying to achieve is the following:
local ModuleScript = require(game.ServerScriptService.ModuleScript)
local Part = ModuleScript:CreatePart("Test")
local OtherPart = ModuleScript:CreatePart("Test2")
Part:SetColor(Color3.new(0, 0, 0), TweenInfo.new(2))
OtherPart:SetColor(Color3.new(1, 1, 1))
I just can’t get it to work, I am stumped and have no clue how to make this system functional. I don’t even know how to describe what I’m asking for, a Module inside of a Module of a ModuleScript? I don’t know.
I’ve tried returning a function and even a self function, making a call to another ModuleScript and I’m just stumped.