My remote event isn't firing properly

So I’m making a combat system and my remote isn’t firing properly. I tried to debug it as much as I could but nothing seems to work.

local character = script.Parent
local humanoid = character.Humanoid
local player = game.Players.LocalPlayer

local uis = game:GetService("UserInputService")
local event = game:GetService("ReplicatedStorage").combat

local LastTimeM1 = 0
local LastTimeM1End = 0
local combo = 1

local canAir = true

local slashAnim = {
	`rbxassetid://15061836689`, -- Slash 1
	`rbxassetid://15061843529`, -- Slash 2
	`rbxassetid://15061846828`, -- Slash 3
	`rbxassetid://15061848868`, -- Slash 4
	`rbxassetid://15061851596`, -- Slash 5
}

local airslashAnim = {
	`rbxassetid://15064976117`, -- Up Slash
	`rbxassetid://15064990418`, -- Down Slash
}

local function hb(size, cframe, ignore, char)
	local hb = Instance.new("Part", workspace.Fx)
	hb.Anchored = true
	hb.CanCollide = false
	hb.Transparency = .6
	hb.Name = "hitbox"
	hb.Material = Enum.Material.ForceField
	hb.CanQuery = false
	hb.Size = size
	hb.CFrame = cframe
	
	local con
	con = hb.Touched:Connect(function()
		con:Disconnect()
	end)
	
	local lasttarg
	
	for i,v in pairs(hb:GetTouchingParts()) do
		if v.Parent:FindFirstChild("Humanoid") and table.find(ignore, v.Parent) == nil then
			if lasttarg then
				if (lasttarg.Position - char.PrimaryPart.Position).Magnitude > (v.Position - char.PrimaryPart.Position) then
					lasttarg = v.Parent.PrimaryPart
				else
					lasttarg = v.Parent.PrimaryPart
				end
			end
		end
	end
	
	hb:Destroy()
	if lasttarg then
		return lasttarg.Parent
	else
		return nil
	end
end

uis.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 and tick() - LastTimeM1 > .5 and tick() - LastTimeM1End > 2 then
		if tick() - LastTimeM1 > 3 then
			combo = 1
		end
		
		LastTimeM1 = tick()
		
		local animation = Instance.new("Animation", workspace.Fx)
		local air = nil
		
		if uis:IsKeyDown("Space") and combo == 4 and canAir then
			canAir = false
			animation.AnimationId = airslashAnim[1]
			air = "Up"
		elseif not uis:IsKeyDown("Space") and combo == 5  and not canAir then
			animation.AnimationId = airslashAnim[2]
			air = "Down"
		else
			animation.AnimationId = slashAnim[combo]
		end
		
		local load = humanoid.Animator:LoadAnimation(animation)
		load:Play()
		
		animation:Destroy()
		
		local hitTarg = hb(Vector3.new(4,6,4), character.PrimaryPart.CFrame * CFrame.new(0,0,-3), {character}, character)
		
		if hitTarg then
			local data = {
				["Target"] = hitTarg, 
				["Character"] = character,
				["Combo"] = combo,
				["Action"] = "m1",
			}
			
			game.ReplicatedStorage.combat:FireServer(data)
		end
		
		if combo == #slashAnim then
			combo = 1
			LastTimeM1End = tick()
		else
			combo += 1
		end
		humanoid.WalkSpeed = 5
		wait(.5)
		humanoid.WalkSpeed = 16
	end
end)

humanoid.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.Landed then
		canAir = true
	end
end)

uis.JumpRequest:Connect(function()
	if tick() - LastTimeM1 < 1 then
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	else
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	end
end)```

Server is over here

```lua


game.ReplicatedStorage.combat.OnServerEvent:Connect(function(client, data)
	print("Ok")
	if data.Action == "m1" then
		data.Target.Humanoid:TakeDamage(3)
		print("m1")
		if data.Air == "Up" then
			
			print("Ok")
			
			local bp = Instance.new("BodyPosition")
			bp.Position = data.Character.PrimaryPart.Position + Vector3.new(0, 30, 0)
			bp.P = 1200
			bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bp.D = 200
			bp.Parent = data.Character.PrimaryPart
			bp.Name = "Position"
			game.Debris:AddItem(bp, 1.5)
			
			local bp2 = Instance.new("BodyPosition")
			bp2.Position = data.Target.PrimaryPart.Position + Vector3.new(0, 30, 0)
			bp2.P = 1200
			bp2.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bp2.D = 200
			bp.Parent = data.Target.PrimaryPart
			bp2.Name = "Position"
			game.Debris:AddItem(bp2, 1.5)
		elseif data.Air == "Down" then
			for i,v in pairs(data.Target.PrimaryPart:GetChildren()) do
				if v:IsA("BodyMover") then
					v:Destroy()
				end
			end
			
			local bv = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv.Velocity = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0,2,0)) * 25
			bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .3)
			
		elseif data.Combo == 5 then
			
			local bv = Instance.new("BodyVelocity", data.Character.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 10
			bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)
			

			local bv2 = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv2.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 75
			bv2.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bv2.Name = "Velocity"
			game.Debris:AddItem(bv2, .2)
			
		end
	end
end)

Can anyone tell me what I did wrong or if I didn’t refer to it properly?

6 Likes

What about it isn’t working? What gets printed to the output? What do you want to achieve?

3 Likes

As @ProgrammerOnCoffee said, what exactly are you expecting it to do? Describe the problem thoroughly and we can help.

3 Likes

Nothing gets printed at all, the remote doesnt fire. I want to know if Im firing it correctly.

3 Likes

Try adding a few prints in the uis.InputBegan function.

2 Likes

The client works. Only issue is firing the event…

3 Likes

try replacing “game.ReplicatedStorage.combat:FireServer(data)” with “game.ReplicatedStorage:WaitForChild(combat):FireServer(data)”

3 Likes

the problem is not on the remote event the problem is on the hitTarg variable because the event is not even firing

3 Likes

Have you tried not using a variable for it, put the line directly in the statment.

2 Likes

Elaborate please… I donr understand

2 Likes

The hitTarg is returning nil,
i’m trying to find out why and fix it

2 Likes

Any update on this? eeeeeeeeee :thought_balloon:

1 Like

its could possibly be the way the statment is set up.

1 Like

Have you tried it yet? Any Update?

1 Like

i fixed it :smiley:,
there was alot of things was wrong in the script
Here is a video that shows the combat :

External Media
1 Like

Can you show the code and air combos?

1 Like

here is the lasttarg variable is set to a nil

after that you are checking lasttarg and the lasttarg was set to nil so here was the problem so for that the hb function was returning nil
anyway here is the scripts

Client Side :

if not game:IsLoaded() then game.Loaded:Wait() end

local character = script.Parent
local humanoid = character.Humanoid
local player = game.Players.LocalPlayer

local uis = game:GetService("UserInputService")
local event = game:GetService("ReplicatedStorage").combat

local LastTimeM1 = 0
local LastTimeM1End = 0
local combo = 1

local canAir = true

local slashAnim = {
	`rbxassetid://15061836689`, -- Slash 1
	`rbxassetid://15061843529`, -- Slash 2
	`rbxassetid://15061846828`, -- Slash 3
	`rbxassetid://15061848868`, -- Slash 4
	`rbxassetid://15061851596`, -- Slash 5
}

local airslashAnim = {
	`rbxassetid://15064976117`, -- Up Slash
	`rbxassetid://15064990418`, -- Down Slash
}

local function hbFun(size, cframe, ignore, char)
	
	local hb = Instance.new("Part")
	hb.Anchored = true
	hb.CanCollide = false
	hb.Transparency = .5 --// change this to 1 when you finish testing the hitbox
	hb.Name = "hitbox"
	hb.Material = Enum.Material.ForceField
	hb.CanQuery = false
	hb.Size = size
	hb.CFrame = cframe
	hb.Parent = workspace.Fx

	local con
	con = hb.Touched:Connect(function()
		con:Disconnect()
	end)

	local lasttarg

	for i,v in pairs(hb:GetTouchingParts()) do
		if v.Parent:FindFirstChild("Humanoid") and table.find(ignore, v.Parent) == nil then
			if lasttarg then
				--// i didn't understand what you want to do here so i will just comment it
				--// Maybe if you explained more i could help you here
				--if (lasttarg.Position - char.PrimaryPart.Position).Magnitude > tonumber(v.Position - char.PrimaryPart.Position) then
					lasttarg = v.Parent.PrimaryPart
				--end	
			else
				lasttarg = v.Parent.PrimaryPart
			end
		end
	end
	
	game.Debris:AddItem(hb,0.3)
	
	if lasttarg then
		return lasttarg.Parent
	else
		return nil
	end
end

uis.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 and tick() - LastTimeM1 > .5 and tick() - LastTimeM1End > 2 then
		if tick() - LastTimeM1 > 3 then
			combo = 1
		end

		LastTimeM1 = tick()

		local animation = Instance.new("Animation", workspace.Fx)
		local air = nil

		if uis:IsKeyDown("Space") and combo == 4 and canAir then
			canAir = false
			animation.AnimationId = airslashAnim[1]
			air = "Up"
		elseif not uis:IsKeyDown("Space") and combo == 5  and not canAir then
			animation.AnimationId = airslashAnim[2]
			air = "Down"
		else
			animation.AnimationId = slashAnim[combo]
		end

		local load = humanoid.Animator:LoadAnimation(animation)
		load:Play()

		animation:Destroy()

		local hitTarg = hbFun(Vector3.new(4,6,4), character.PrimaryPart.CFrame * CFrame.new(0,0,-3), {character}, character)
		
		if hitTarg then
			local data = {
				["Target"] = hitTarg, 
				["Character"] = character,
				["Combo"] = combo,
				["Action"] = "m1",
			}

			game.ReplicatedStorage.combat:FireServer(data)
		end

		if combo == #slashAnim then
			combo = 1
			LastTimeM1End = tick()
		else
			combo += 1
		end
		humanoid.WalkSpeed = 5
		task.wait(.5)
		humanoid.WalkSpeed = 16
	end
end)

humanoid.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.Landed then
		canAir = true
	end
end)

uis.JumpRequest:Connect(function()
	if tick() - LastTimeM1 < 1 then
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	else
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	end
end)

Server side :

game.ReplicatedStorage.combat.OnServerEvent:Connect(function(client, data)
	print("Ok")
	print(data)
	if data.Action == "m1" then
		data.Target.Humanoid:TakeDamage(3)
		print("m1")
		if data.Air == "Up" then

			print("Ok")

			local bp = Instance.new("BodyPosition")
			bp.Position = data.Character.PrimaryPart.Position + Vector3.new(0, 30, 0)
			bp.P = 1200
			bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bp.D = 200
			bp.Parent = data.Character.PrimaryPart
			bp.Name = "Position"
			game.Debris:AddItem(bp, 1.5)

			local bp2 = Instance.new("BodyPosition")
			bp2.Position = data.Target.PrimaryPart.Position + Vector3.new(0, 30, 0)
			bp2.P = 1200
			bp2.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bp2.D = 200
			bp.Parent = data.Target.PrimaryPart
			bp2.Name = "Position"
			game.Debris:AddItem(bp2, 1.5)
		elseif data.Air == "Down" then
			for i,v in pairs(data.Target.PrimaryPart:GetChildren()) do
				if v:IsA("BodyMover") then
					v:Destroy()
				end
			end

			local bv = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv.Velocity = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0,2,0)) * 25
			bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .3)

		elseif data.Combo == 5 then

			local bv = Instance.new("BodyVelocity", data.Character.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 10
			bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)


			local bv2 = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv2.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 75
			bv2.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bv2.Name = "Velocity"
			game.Debris:AddItem(bv2, .2)

		end
	end
end)

that’s it if you need any help just let me know

Thanks a lot :pray: I will be checking it right now.

1 Like

Sorry for the late response but when I tried it the air combat ended up not working, I realized I forgot to fire the air in data but when I tried it only the enemy went up, here is what I mean.

External Media

Here is the code once again.

game.ReplicatedStorage.combat.OnServerEvent:Connect(function(client, data)
	print("Ok")
	print(data)
	if data.Action == "m1" then
		data.Target.Humanoid:TakeDamage(3)
		print("m1")
		if data.Air == "Up" then

			print("Up")

			local bp = Instance.new("BodyPosition")
			bp.Position = data.Character.PrimaryPart.Position + Vector3.new(0, 30, 0)
			bp.P = 1200
			bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bp.D = 200
			bp.Parent = data.Character.PrimaryPart
			bp.Name = "Position"
			game.Debris:AddItem(bp, 1.5)

			local bp2 = Instance.new("BodyPosition")
			bp2.Position = data.Character.PrimaryPart.Position + Vector3.new(0, 30, 0)
			bp2.P = 1200
			bp2.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bp2.D = 200
			bp.Parent = data.Target.PrimaryPart
			bp2.Name = "Position"
			game.Debris:AddItem(bp2, 1.5)
		elseif data.Air == "Down" then
			for i,v in pairs(data.Target.PrimaryPart:GetChildren()) do
				if v:IsA("BodyMover") then
					v:Destroy()
				end
			end

			local bv = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv.Velocity = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0,2,0)) * 25
			bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .3)

		elseif data.Combo == 5 then

			local bv = Instance.new("BodyVelocity", data.Character.PrimaryPart)
			bv.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 10
			bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bv.Name = "Velocity"
			game.Debris:AddItem(bv, .2)


			local bv2 = Instance.new("BodyVelocity", data.Target.PrimaryPart)
			bv2.Velocity = data.Character.PrimaryPart.CFrame.LookVector * 75
			bv2.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			bv2.Name = "Velocity"
			game.Debris:AddItem(bv2, .2)

		end
	end
end)```