I made a combat punch system using Region3. However, the player you hit gets damage taken from them twice or three times in some cases. It works sometimes but other times no.
Local Script:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local Enabled = true
local RE = script:WaitForChild("Function")
UIS.InputBegan:Connect(function (input, GPE)
if GPE then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if Enabled == true then
RE:FireServer("Combat", char.HumanoidRootPart.CFrame * CFrame.new(0,0,-2.5).Position)
Enabled = false
wait(0.3)
Enabled = true
end
end
end)
Server Script:
local RE = script.Parent
local Enabled = true
local combo = 1
RE.OnServerEvent:Connect(function(player, action, Pos)
local char = player.Character or player.CharacterAdded:Wait()
if Enabled == false then return end
Enabled = false
if action == "Combat" then
if combo == 1 then
combo = 2
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://7008354558"
local Anim = char.Humanoid:LoadAnimation(Track)
Anim:Play()
local playingTracks = char.Humanoid.Animator:GetPlayingAnimationTracks()
for i, v in pairs(playingTracks) do
if v.Name == "walk" or v.Name == "run" then
v:Destroy()
end
end
elseif combo == 2 then
combo = 1
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://7008358588"
local Anim = char.Humanoid:LoadAnimation(Track)
Anim:Play()
local playingTracks = char.Humanoid.Animator:GetPlayingAnimationTracks()
for i, v in pairs(playingTracks) do
if v.Name == "walk" or v.Name == "run" then
v:Destroy()
end
end
end
if char.Humanoid:FindFirstChild("Whoosh") then
local whoosh = char.Humanoid:WaitForChild("Whoosh")
whoosh:Play()
else
local sound = Instance.new("Sound", char.Humanoid)
sound.Name = "Whoosh"
sound.SoundId = "rbxassetid://231731980"
sound.PlaybackSpeed = math.random(88, 120)/100
sound:Play()
end
wait(0.2)
local region = Region3.new(Pos - Vector3.new(2.5, 2.5, 2.5), Pos + Vector3.new(2.5, 2.5, 2.5))
local RTable = workspace:FindPartsInRegion3(region, nil, 20)
for i, v in pairs(RTable) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("Deb") == nil and v.Parent ~= char then
local Deb = Instance.new("BoolValue", v.Parent)
Deb.Name = "Deb"
game.Debris:AddItem(Deb, 0.2)
local randomDMG = math.random(20,25)
v.Parent.Humanoid:TakeDamage(randomDMG)
print(randomDMG)
if v:FindFirstChild("Punch") then
local punch = v:WaitForChild("Punch")
punch:Play()
else
local s = Instance.new("Sound", v)
s.Name = "Punch"
s.SoundId = "rbxassetid://3932505023"
s.PlaybackSpeed = math.random(88, 120)/100
s:Play()
end
local attachment1 = Instance.new("Attachment", v)
local fx = game.ServerStorage:WaitForChild("FX")
local punchFX = fx:WaitForChild("PUNCH")
local random = math.random(0, 2)
if random == 1 then
local particle = punchFX.Effects2:Clone()
particle.Parent = attachment1
particle:Emit(10)
wait(0.2)
particle:Destroy()
print("ELLLO")
elseif random == 2 then
local particle = punchFX.HitModuleParticle:Clone()
particle.Parent = attachment1
particle:Emit(10)
wait(0.2)
particle:Destroy()
print("ELLO 2")
end
end
end
wait(0.3)
Enabled = true
end
end)

1 comment
Just Use Debounce Or Smthing