Hey there, at the minute, I’m making a module and I’m getting a weird problem. I’m trying to protect my events from being changed, however, every function I call errors with attempt to call a nil value
. There has to be something I’m missing right? This is the module script:
function interaction.new()
local newint = {}
newint.Adornee = nil
newint.TextDelay = 0.1
setmetatable(newint, interaction)
local eventProxy = {}
local mt = {}
mt.__index = newint
mt.__newindex = function(tbl, key, val)
local suc, err = pcall(function() key:Connect(function() print("hi") end) end)
if suc then
print(suc)
end
if err then
warn(err)
end
if pcall(function() key:IsA("BindableEvent") end) or pcall(function() key:Connect(function() end) end) then
error("Attempt to change an event.")
else
print(key, val)
rawset(tbl, key, val)
end
end
mt.__metatable = function() error("Attempt to access metatable") end
setmetatable(eventProxy, mt)
newint.SpeakFinishedBind = Instance.new("BindableEvent")
newint.SpeakTextChangedBind = Instance.new("BindableEvent")
newint.SpeakTextChanged = newint.SpeakTextChangedBind.Event
newint.OnSpeakFinished = newint.SpeakFinishedBind.Event
return eventProxy
end
and here’s where I’m changing the values:
local commMod = require(script.CommunicationModule)
local interaction = commMod.new()
interaction.Adornee = script.Parent.TextLabel
interaction.TextDelay = 0.03
interaction.SpeakFinishedBind = "aaaa"
interaction.SpeakTextChanged = true
interaction.SpeakTextChanged:Connect(function()
print("Text has been changed by :Speak() function!")
end)
interaction.OnSpeakFinished:Connect(function()
warn("Finished speaking!")
end)
interaction:Speak("Minecraft sucks. My reasoning to that is because it just doesn't have the same WOW it had to it in 1973. Sure, it's got a ton of new features but I feel like that just over complicates it. You feel me?", true)
print("aaaaa")
I’ve also read this article in hopes of finding a possible answer, however it’s 7 years old and doesn’t really describe much.