Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- FireServer logger for a specific RemoteEvent named "shoot_event"
- -- Logs every call (even from your own scripts), with readable args.
- local HttpService = game:GetService("HttpService")
- local function shortInstancePath(inst)
- if typeof(inst) ~= "Instance" then return nil end
- local ok, full = pcall(function() return inst:GetFullName() end)
- return ok and full or (inst.ClassName .. "?" )
- end
- local function dump(v, depth)
- depth = depth or 0
- if depth > 2 then return "<max-depth>" end
- local t = typeof(v)
- if t == "number" or t == "boolean" or t == "nil" then
- return tostring(v)
- elseif t == "string" then
- return ('"%s"'):format(v)
- elseif t == "Vector3" then
- return ("Vector3(%.3f, %.3f, %.3f)"):format(v.X, v.Y, v.Z)
- elseif t == "Vector2" then
- return ("Vector2(%.3f, %.3f)"):format(v.X, v.Y)
- elseif t == "CFrame" then
- local p = v.Position
- return ("CFrame(p=(%.3f, %.3f, %.3f))"):format(p.X, p.Y, p.Z)
- elseif t == "Instance" then
- return ("Instance(%s)@%s"):format(v.ClassName, shortInstancePath(v) or "?")
- elseif t == "table" then
- local parts, n = {}, 0
- for k,val in pairs(v) do
- n += 1
- if n > 10 then table.insert(parts, "..."); break end
- table.insert(parts, ("%s=%s"):format(dump(k, depth+1), dump(val, depth+1)))
- end
- return "{" .. table.concat(parts, ", ") .. "}"
- else
- -- Fallback (userdata, RBXScriptSignal, etc.)
- local ok, json = pcall(function() return HttpService:JSONEncode(v) end)
- return ok and json or ("<%s:%s>"):format(t, tostring(v))
- end
- end
- -- Hook __namecall
- local old
- old = hookmetamethod(game, "__namecall", function(self, ...)
- local method = getnamecallmethod()
- -- Remove the checkcaller() filter so we log LOCAL calls too.
- if method == "FireServer" and tostring(self) == "shoot_event" then
- local args = table.pack(...)
- local lines = {}
- for i = 1, args.n do
- lines[i] = ("Arg %d: %s"):format(i, dump(args[i]))
- end
- warn(("[%.2f] FireServer -> %s"):format(os.clock(), shortInstancePath(self) or tostring(self)))
- print(table.concat(lines, "\n"))
- end
- return old(self, ...)
- end)
- -- (Optional) also see RemoteFunction:InvokeServer calls for the same object, if relevant.
- -- oldInvoke hook example:
- -- local oldInvoke = hookmetamethod(game, "__namecall", function(self, ...)
- -- local method = getnamecallmethod()
- -- if method == "InvokeServer" and tostring(self) == "shoot_event" then ... end
- -- return oldInvoke(self, ...)
- -- end)
Advertisement
Add Comment
Please, Sign In to add comment