Trouble with Remote Events/Combat System

Basically, I’m trying to figure out why my debounces are universal for every player. Whenever one player tries to punch, it disables the combat for the other player and vice-versa.

I’ve already tried moving the script to StarterCharacterScripts, and at this point I’m extremely lost.

Directory: gyazo.com/12896aa169f793795a370472b8ff5b63

CODE:

--client
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local UIS = game:GetService("UserInputService")

--combat
mouse.Button1Down:Connect(function()
	game.ReplicatedStorage.combore:FireServer({Fire = "Combat", Type = "Light"})
end)

--blocking
UIS.InputBegan:Connect(function(input, gpe)
	if input.KeyCode == Enum.KeyCode.F and not gpe then
		game.ReplicatedStorage.combore:FireServer({Fire = "Block", Type = true})
	end
end)

UIS.InputEnded:Connect(function(input, gpe)
	if input.KeyCode == Enum.KeyCode.F and not gpe then
		game.ReplicatedStorage.combore:FireServer({Fire = "Block", Type = false})		
	end
end)

--server
local damage = require(game.ServerScriptService.Modules.Damage)
local region = require(game.ServerScriptService.Modules.RotatedRegion3)
local combo = 0
local last = tick()

local block = false
local cd = false
local anims = game.ReplicatedStorage.anims
local sounds = game.ServerStorage.Sounds

CombatInfo = {
	Damage = 5,
	Stun = 0.5,
	Knockback = 7,
	KnockbackDir = nil	
	}

local hitbox = function(char, tab)
	local victim = {}
	for _, v in pairs(workspace.humans:GetChildren()) do
		local reg = region.new(char.HumanoidRootPart.CFrame * CFrame.new(0,0,-3), 4.27, 3.24, 5.49)
		if reg:castPart(v:FindFirstChild("HumanoidRootPart")) then
			if not v:FindFirstChild("Blocking") then
				local hit = sounds.hit:Clone()
				game:GetService("Debris"):AddItem(hit, .6)
					hit.Parent = char
				table.insert(victim, v)
				damage.Handle(victim, tab)
				hit:Play()
			else
				local blockse = sounds.blocksound:Clone()
				blockse.Parent = char
				blockse:Play()
				game:GetService("Debris"):AddItem(blockse, .5)		
			end
		end
	end
end

game.ReplicatedStorage.combore.OnServerEvent:Connect(function(player, args)
if cd then return end

local char = player.Character
local hum = char.Humanoid
local blockanim = hum:LoadAnimation(anims.block)

if args.Fire == "Combat" and not block then
cd = true

local currinfo = {Hitter = player.Name}

for i,v in next, CombatInfo do
	currinfo[i] = v
end

if not currinfo.KnockbackDir then
	currinfo.KnockbackDir = player.Character.HumanoidRootPart.CFrame.LookVector * 1
end

local ok = function()
	if args.Type == "Light" then
		local anim = hum:LoadAnimation(anims["hit"..combo])
		local woosh = sounds.woosh:Clone()
			woosh.Parent = char
				woosh:Play()
				anim:Play()							
					wait(.3)
				hitbox(char, currinfo)
				combo = combo + 1
			print(combo)		
		wait(.15)
	woosh:Destroy()
	cd = false
	end
end	

if tick() - last and combo < 2 then
	ok()
else
	combo = 0
	ok()	
end		
last = tick()		

elseif args.Fire == "Block" and args.Type then
local blockfold = Instance.new("Folder", char)
		blockanim:Play()
			block = true
		hum.WalkSpeed = 9
	blockfold.Name = "Blocking"	
print("Block")		

elseif args.Fire == "Block" and not args.Type then
blockanim:Stop()
		hum.WalkSpeed = 16
			game:GetService("Debris"):AddItem(char:FindFirstChild("Blocking"), .1)
		block = false
	print("Unblock")
	end	
end)

All help is appreciated.

Is this the code from the combocounter script or the localcom script?

I labeled with comments which one is client, and which one is server-sided.

Hey UltraSkiMask,
You have a variable called ‘cd’ set to to false and whenever the event is fired. The server checks if this value is true, if so then return out the function. If it’s false then it sets it to true. The server script handles every single client. You clearly only have on event that EVERY CLIENT can fire. This must mean that when a client fires this event. Every single serverscript that handles this ONE EVENT will get fired therefore disabling combat for each player.

It would be best to either: remoteevent for each client OR create a dictionary that stores a key and a value. The key would be the player and the value would be the true or false value. I’d advise to add the player in playeradded and then remove in playerremoving

Example:

local debounces = {}

game.Players.PlayerAdded:Connect(function(plr)
debounces[plr] = false
end

game.Players.PlayerRemoving:Connect(function(plr)
debounces[plr] = nil
end

Example Usage:

if debounces[plr] == true then return end
– If passed, debounces[plr] == false so set it tot rue
debounces[plr] = true

3 Likes

Thank you so much! I understand what I need to do now, this was VERY much appreciated!

1 Like

can you explain the examples a little more clearly please.