Question about event

Does exist an event that can fire everytime when child properties getting read by other script or something similiar, such same as “Child.Changed” but with other mechanic.
Or should i do this through metatables?

Any answer could help, because i ran out of ideas in my scripting plan.

3 Likes

There’s no such event. What are you trying to do? I think there might be a better approach than detecting when variables get read.

Here’s how you’d do it though:

local t = {
    OnMemberRead = Signal.new(),
    OnMemberWrite = Signal.new()
}
local interfaceMT = {
    __index = function(self, key)
        print("index", key, rawget(self, key))
        t.OnMemberRead:Fire(key)
        return t[key]
    end,
    __newindex = function(self, key, value)
        print("newindex", key, value)
        t.OnMemberWrite:Fire(key, value)
        t[key] = value
    end
}
local interface = setmetatable({}, interfaceMT)

--Test stuff:
interface.A = "test"
interface.A = "test"
print(interface.A)
print(interface.B)

It’s important that interface is a completely empty table, because __newindex and __index only fire when a nil member is written or read, respectively. The user t would never actually get access to t, only to interface. So if this were a module you’d return interface. If you wanted to add functionality like member variables or methods, you’d add them to 'tand **not** tointerface`. Oh and you’d probably remove the print statements, and you’ll want to use a Signal class to implement your own custom events. Check out this post: Lua Signal Class Comparison & Optimal `GoodSignal` Class

2 Likes

Hello, thanks for code, it works of course! But my idea was doing event fire when variable getting read, in my way this is some part of workspace. When that part getting read by other local script, happens fire event or some action. Probably you dont understand what i mean? Alright, i’m trying to make anti-dex explorer… That may sound impossible but i trust to, i can make at least something.

In my head that looks like:

  • I’m making necessary part that gotta be created on client’s PC.

  • I Connect part to functions that when it gets manually deleted or replaced - it kicks player.

  • My Part binds to that metatable when part getting read on other script - it kicks player.

  • Code will be hidden on important script where player can’t disable or delete script in any way.

There some logic, this part will not be read anymore. When player injects Dex-explorer this part getting read by his exploit meanwhile player getting kicked.
Again thanks for code!

Сonclusion:
Script works but i need code that kicks player when part getting read by other local script, and yes, is it possible?
I hope yes.

Have a great day!

1 Like

No, I’m fairly certain there’s no way to force scripts created by exploiters to only access a wrapper to an object rather than the object itself. You can get the metatable of instances but it’s locked so AFAIK there’s nothing to do.

1 Like

Okay, thanks for code, i think i gonna use it somewhere.