Skip to content

Custom Instance

c edited this page Oct 31, 2021 · 3 revisions

The custom instance script is a script that allows you to make custom instances. Pretty self-explanatory. The script provides you with a function that takes in a ClassName string, a properties table with customizability, an events table that is used as instance events, and a functions table that defines what functions the instance holds.

Setup

To first get the script running first, you want to run the following

loadstring(game:HttpGet("https://raw.githubusercontent.com/ceat-ceat/roblox-script-utils/main/fakebindable.lua"))()

This will assign a function to _G.BaseInstance where you can make your own instances

_G.BaseInstance

Functions

Custom Instance _G.BaseInstance.new(ClassName string ,Properties table, Events table, Functions table)

Returns a custom instance with the given, properties, events, and table. The "Name" property is set to the given ClassName as default and the custom instance is given a "Changed" event by default.

Properties Table Layout

local properties = {
  PropertyName = {
    ReadOnly = false,
    Value = 2,
    Filter = function(newvalue)
        assert(tostring(newvalue))
        return newvalue
      end
    }
}

Events Table Layout

loadstring(game:HttpGet("https://raw.githubusercontent.com/ceat-ceat/roblox-script-utils/main/fakebindable.lua"))()
local event = _G.FakeBindable.new()
local events = {
  EventName = event.Event
}

Functions Table Layout

local functions = {
  FunctionName = function(self,...)
    print(...)
  end
}

Sample Code

local baseinstance = loadstring(game:HttpGet("https://raw.githubusercontent.com/ceat-ceat/roblox-script-utils/main/fakebindable.lua"))()
loadstring(game:HttpGet("https://raw.githubusercontent.com/ceat-ceat/roblox-script-utils/main/fakebindable.lua"))()

-- instance setup

local ValueChanged = _G.FakeBindable.new()
local new = baseinstance.new("deez",{
  Value = {
    Value = "default",
    Filter = function(newvalue)
      return tostring(newvalue)
    end
  },
  Value2 = {
    ReadOnly = true,
    Value = 10
  }
},{
  ValueChanged = ValueChanged.Event
},{
  DoSomething = function(self)
    return self.Value
  end
})
new.Changed:Connect(function(prop,val)
  if prop == "Value" then
    ValueChanged:Fire(val)
  end
end)

-- instance usage

new.ValueChanged:Connect(function(newvalue)
  print(newvalue)
end)
new:DoSomething()
print(new.Value,new.Value2)
new.Value = 2
print(new.Value)
new.Value2 = "aaaa" -- errors

Events in the event table can be any event! It doesn't have to be a fake one