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?