1 == 1 is equal to false? (Edit: nvm)

I have this module:

local Remote = script.RemoteEvent

local Ping = {}
function Ping.new()
	return setmetatable({
	--Properties:
	ID = 1,
	},{
	--Index Class:
	__index = Ping
	})
end

function Ping:Connect(fn)
	return Remote.OnServerEvent:Connect(function(OtherID, ...)
		print("Recieved")
		if OtherID == self.ID then
			print("Similiar")
			task.spawn(fn(...))
		end
	end)
end

function Ping:Fire(...)
	Remote:FireServer(self.ID, ...)
end

return Ping

Which I use in this module:

local Ping = require(script.Parent.Ping)
local PingList = {}
PingList.Printer = Ping.new()

return PingList

Which I use in this server script:

local PingList = require(game:GetService("ReplicatedStorage").PingList)
PingList.Printer:Connect(function(Printer)
	print(Printer)
end)

Which I send an event a to using this local script:

local RS = game:GetService("ReplicatedStorage")
local PingList = require(RS.PingList)
print(PingList.Printer)
game:GetService("RunService").Heartbeat:Connect(function()
	PingList.Printer:Fire("EEE")
end)

Before asking if self.ID == ID, I put a print there and it printed meaning some OOP wizardry happened that need help understanding…

Edit: Thanks for the help guys.

you are forgetting that the first parameter on OnServerEvent is the player that fired it
in your case it should be return Remote.OnServerEvent:Connect(player, OtherID, ...)

xHeptc is correct, you’re missing the player as the first parameter of OnServerEvent.

You’ll also need to change your task.spawn syntax from this

to this

task.spawn(fn, ...)

Unless you intend your function to return another function, which isn’t how you have it set up.

1 Like

he doesn’t really need task.spawn since its a signal, not a callback

1 Like

Great point. OnServerEvent is already starting a new pseudothread, so unless you care about concurrency within that response, you can just call fn(...) directly.

1 Like

Thank you so much <3!!!
charcharchar

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.