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
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.
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.
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.