Skip to content

Commit

Permalink
Fix remote counter desync
Browse files Browse the repository at this point in the history
  • Loading branch information
hoontee committed Jan 11, 2025
1 parent 6811d5a commit 1a2a8b0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions Pronghorn/Remotes/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ local IS_CLIENT = RunService:IsClient()

-- Objects
local remotesFolder: Folder;
local numClientRemotesLoaded = 0
local clientRemotesLoadedEvent = New.Event()

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Helper Functions
Expand Down Expand Up @@ -133,12 +131,18 @@ local function connectEventClient(remote: RemoteFunction | UnreliableRemoteEvent
(remote :: RemoteEvent):FireServer(...)
end
end
end

local function haveClientEventsLoaded(): boolean
local numClientEventsLoaded = 0

numClientRemotesLoaded += 1

if numClientRemotesLoaded == script:GetAttribute("NumRemotes") then
clientRemotesLoadedEvent:Fire()
for _, instance in remotesFolder:GetDescendants() do
if instance:IsA("BaseRemoteEvent") or instance:IsA("RemoteFunction") then
numClientEventsLoaded += 1
end
end

return numClientEventsLoaded == script:GetAttribute("NumRemotes") :: number
end

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -178,8 +182,10 @@ function Remotes.Server:CreateToClient(name: string, requiredParameterTypes: {st
Remotes.Server[moduleName][remote.Name] = actions :: ServerRemote

actions.Destroy = function(): ()
if not Remotes.Server[moduleName][remote.Name] then return end
remote:Destroy()
Remotes.Server[moduleName][remote.Name] = nil
script:SetAttribute("NumRemotes", (script:GetAttribute("NumRemotes") :: number? or 0) - 1)
end

if remoteType == "Returns" then
Expand Down Expand Up @@ -264,8 +270,10 @@ function Remotes.Server:CreateToServer(name: string, requiredParameterTypes: {st
end

actions.Destroy = function(): ()
if not Remotes.Server[moduleName][remote.Name] then return end
remote:Destroy()
Remotes.Server[moduleName][remote.Name] = nil
script:SetAttribute("NumRemotes", (script:GetAttribute("NumRemotes") :: number? or 0) - 1)
end

if remoteType == "Returns" then
Expand Down Expand Up @@ -296,7 +304,7 @@ function Remotes:Init()
if IS_SERVER then
remotesFolder = New.Instance("Folder", ReplicatedStorage, "__remotes")

RunService.Heartbeat:Connect(function(_dt: number)
RunService.Heartbeat:Connect(function(_dt: number): ()
script:SetAttribute("ServerTime", os.clock())
end)
else
Expand All @@ -308,15 +316,13 @@ function Remotes:Init()
connectEventClient(remote :: any)
end

remotesFolder.DescendantAdded:Connect(function(remote)
remotesFolder.DescendantAdded:Connect(function(remote: Instance): ()
if not (remote:IsA("RemoteFunction") or remote:IsA("UnreliableRemoteEvent") or remote:IsA("RemoteEvent")) then return end

connectEventClient(remote :: any)
end)

if numClientRemotesLoaded < script:GetAttribute("NumRemotes") :: number then
clientRemotesLoadedEvent:Wait()
end
while not haveClientEventsLoaded() do task.wait() end
end
end

Expand Down
2 changes: 1 addition & 1 deletion Pronghorn/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
║ ██████▀██▓▌▀▌ ▄ ▄▓▌▐▓█▌ ║
║ ║
║ ║
║ Pronghorn Framework Rev. B83
║ Pronghorn Framework Rev. B84
║ https://github.com/Iron-Stag-Games/Pronghorn ║
║ GNU Lesser General Public License v2.1 ║
║ ║
Expand Down

0 comments on commit 1a2a8b0

Please sign in to comment.