So I’m making a project where the server fires an event to the client, which then fires back to the server, ending the loop. I then realized that when I’m in testing mode with Server and Clients (this is an important detail) my client only prints out my “Debug” line once, but the server does it twice. This leads me to believe my client is sending the message back to the server twice, for some reason.
Maybe it’s lag or maybe just a little bug. The thing is, I don’t know.
LocalScript code related to that:
AttackEvent.OnClientEvent:Connect(function()
print('CALLED THE CLIENT')
local PickedAnim = Animations[math.random(1, #Animations)]
local Track = Character.Humanoid.Animator:LoadAnimation(PickedAnim)
Track:Play()
Track:AdjustSpeed(2)
wait(0.25)
AttackEvent:FireServer(Character:WaitForChild('HumanoidRootPart').CFrame)
end)
Server Script code related to that:
local function Slash()
if Db == false then
Db = true
AttackEvent:FireClient(Player)
end
end
AttackEvent.OnServerEvent:Connect(function(Player, ReturnedCFrame)
print('CALLED SERVER')
Sounds.Slash:Play()
Sounds.Slash.TimePosition = 0.39
local HitCharacter = AttackModule.ray(ReturnedCFrame, 4, Player.Character or Player.CharacterAdded:Wait())
if HitCharacter then
local HitSound = Sounds.Kerplunk:Clone()
HitSound.Parent = HitCharacter.HumanoidRootPart
HitSound:Play()
HitCharacter.Humanoid.Health -= 15
end
wait(2)
Db = false
end)
Both scripts are inside of a Tool, by the way.
OUTPUT:
(server)
CALLED SERVER
CALLED SERVER
(client who fired the event)
CALLED CLIENT
Thanks in advance!
PS: I was just testing this out, and turns out that when I reset character, even if I’m doing normal testing, the more times I reset, the more times it fires back. Maybe it has something to do with the amount of characters in the server or something? I was testing with 2 clients, by the way. ANOTHER ADDITION HERE: I’m using a system where players leave their ragdolled bodies after resetting, and the “extra times” seem to disappear when the ragdoll vanishes. Maybe it has something to do with the amount of Tools existing inside of the workspace?