Server-Client Communication for my Weapon System

I’m trying to make a weapon system that’s OOP, but the problem is that I can’t figure out how to make the server communicate to the client.

This problem seems really simple, although It’s because of OOP that I can’t figure out how to make it work.

I’m basically creating a new weapon object with a function: Weapon.new(), and it creates two remote events:

EventAttackIn = Instance.new("RemoteEvent"),
EventAttackOut = Instance.new("RemoteEvent"),

I need to use these events to check whenever someone requests to attack.

Here is the function that uses the remotes:

unction Weapon.hitDetection(self: Weapon, player ,DetectionInfo: Dictionary)
	
	self.LatestAttackNumber += 1
	local AttackID = self.LatestAttackNumber

	local ReturnTargets = {}
	local OnReturnedHit

	OnReturnedHit = self.EventAttackOut.OnServerEvent:Connect(function(givenedPlayer,givenedId,GivenTargets)
		if givenedPlayer == player and givenedId == AttackID then -- Make sure it's our client and our attack.
			ReturnTargets = GivenTargets
		end
	end)
	--//Fire to client.
	self.EventAttackIn:FireClient(player,AttackID,DetectionInfo)

	--//Wait to disconnect function
	local startTime = os.clock()
	while (startTime + self.AttackRate > os.clock()) and #ReturnTargets == 0 do task.wait(0.05) 

		OnReturnedHit:Disconnect()
		return ReturnTargets --//The data should now be processed elsewhere to apply damage.
	end
end
1 Like

Wait are you creating the events in the scripts and not setting the parent?

SET THE PARENT

If it’s not set you can’t replicate to clients because it’s not found anywhere in the hierarchy

OP is unclear. What exact issue are you having? “Cant communicate with client” could mean an abundance of things?

Are you struggling because passing OOP objects over client server boundary can be finnicky?

What I was planning to do was to fire a remote to the client to allow the client to receive the remotes, but it just got too complicated and it was probably really inefficient. So I don’t know any other good way of doing it.

This is still pretty vague.

It may help for you to understand that your system cannot be entirely OOP. Some root script has to act as the main thread that receives the signal from the server. A basic OOP structure to handle FX on the client is as follows.

FX → OOP Module that handles FX from one bullet hit.
FX Handler → OOP Module that receives remote event, creates a corresponding FX for each.

Local Script → Instantiates and initializes FX Handler

This model is great to learn and visualize the concept.

Although, in this case, the FX handler is just overhead as there is no reason I can think of to make the handler object oriented, since it would only be instantiated once. The handler logic can more simply be left to the local script.

Here is what I was trying to do. I wanted to make a tool that only had a server script in it and was able to communicate to the client using a networker called Packet. Although, the networker that I use kind of sucks since it lacks flexibility. This led to me putting a local script and some remote events in the tool, which I should have done at the start since it would have been much more easier. For a better reference, here is some pictures of what I wanted to do.

Original Plan

Screenshot 2025-10-17 233355

Last Resort

I’m not so sure how OOP works, so the only information that I have about it right now comes from this RobloxLearn youtube video. Basically, my weapon class looks almost identical to what Stephen wrote in the video, but obviously I change the functions and classes.