So I’m making a fighting game and working with hit detection. Currently I have a basic outline of an attack. But it hits multiple times, Because it hits multiple body parts which makes it hurt the player multiple times.
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local c = Player.Character
local mouse = Player:GetMouse()
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local cdtime = 2
local cd = false
UIS.InputBegan:connect(function(input,typing)
if typing then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 and cd == false then
cd = true
game.ReplicatedStorage.HitBox:FireServer(c.Humanoid,c.HumanoidRootPart,c.HumanoidRootPart.CFrame * CFrame.new(0,0,-4),5,Player.Name)
local light1 = c.Humanoid:LoadAnimation(script:WaitForChild("light1"))
light1:Play()
wait(cdtime)
cd = false
end
RS.RenderStepped:connect(function()
end)
end)
Local code ^
game.ReplicatedStorage.HitBox.OnServerEvent:Connect(function(player,hum,Part,hitboxcfr,dmg,exclude)
local deb = false
--local chr = player.Character or player.CharacterAdded:Wait()
local HitBox = Instance.new("Part")
HitBox.Parent = player.Character
HitBox.Anchored = true
HitBox.CanCollide = false
HitBox.Transparency = .5
HitBox.Name = "HitBox"
HitBox.BrickColor = BrickColor.new("Bright red")
HitBox.CFrame = hitboxcfr
HitBox.Size = Vector3.new(2,5,2)
game.Debris:AddItem(HitBox, .5)
local h = nil
HitBox.Touched:Connect(function(h)
print(h)
if h.Parent:FindFirstChild('Humanoid') and h.Parent.Name ~= exclude and deb == false then
local Enemy = h.Parent.Humanoid
if deb == false then
Enemy:TakeDamage(dmg)
local position = Instance.new("BodyVelocity",player.Character.HumanoidRootPart)
position.MaxForce = Vector3.new(1000000000,1000000000,1000000000)
position.P = 100
position.Velocity = player.Character.HumanoidRootPart.CFrame.LookVector * .05
game.Debris:AddItem(position,1)
Enemy.AutoRotate = false
wait(.5)
deb = false
Enemy.AutoRotate = true
end
else
end
end)
end)
Server code ^
I have no idea what to try to fix this. Anyone have any ideas?