Please help me get my punch to do damage to players and enemies

Hello, I followed a tutorial online (new to coding) and after about 5 hours today, I managed to get this punching script working pretty well. Sound, an FX, everything. Works great on enemies. My question is can someone please point me in the right direction as to how to get it to also damage another player. I have been googling and researching but trying to take bits and pieces from other tutorials or weapons doesn’t seem to be working. Thanks for any help!

EDIT: (it seems it doesn’t actually damage enemies either. im so confused. sorry. More details below.)

Enabled = true
Combo = 1

script.Parent.OnServerEvent:connect(function(Player, Action, V1)
    local c = Player.Character
    if Enabled == false then return end
    if Action == "Combat" then  
        Enabled = false
        if Combo == 1 then
            Combo = 2
            local Track = Instance.new("Animation")
            Track.AnimationId = "rbxassetid://6374164003"
            local Anim = c.Humanoid:LoadAnimation(Track)
            Anim:Play()
        elseif Combo == 2 then
            Combo = 1
            local Track = Instance.new("Animation")
            Track.AnimationId = "rbxassetid://6374165840"
            local Anim = c.Humanoid:LoadAnimation(Track)
            Anim:Play()
        end
        wait(0.2)
        local Region = Region3.new(V1-Vector3.new(2,2,2),V1*Vector3.new(2,2,2))
        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 ~= c then
                local Deb = Instance.new("BoolValue", v.Parent)
                Deb.Name = "Deb"
                game.Debris:AddItem(Deb,0.2)
                v.Parent.Humanoid:TakeDamage(5)
                local S = Instance.new("Sound", v)
                S.SoundID = "rbxassetid://3932505023"
                S.PlaybackSpeed = math.random(80,120)/100
                S.Play()
                local FX = Instance.new("Part", workspace.FX)
                FX.Name = "CombatHit"
                FX.CanCollide = false
                FX.Anchored = true
                FX.Material = "ForceField"
                FX.Color = Color3.new(1,0,0)
                FX.Size = Vector3.new(1,1,1)
                local SM = Instance.new("SpecialMesh", FX)SM.MeshType = "Sphere"
                SM.Scale = Vector3.new(0,0,0)
                FX.CFrame = v.Parent.HumanoidRootPart.CFrame*CFrame.new(math.random(-20,20)/10,math.random(-20,20)/10,math.random(-20,20)/10)
            end
        end
        wait(0.31)
        Enabled = true
    end
end)
1 Like

This script is way too long, it could’ve been a way shorter script. I can’t help soz. Insttead of Combo you couldve used a letter

1 Like

This should already be enough to damage other players because it looks for a Humanoid to damage indiscriminately based on a region cast. What happens when you try to use this system on other players and how does that compare to when you use it with NPCs? Any errors or media that you can share about it as well? Need more details.

@P097B Not helpful. Also, opting for a letter instead of a full word botches code readability, so no I think the script is fine how it is to use a full word over a letter.

2 Likes

Ok so apparently I am wrong. It doesn’t actually damage enemies after all after doing some testing. :frowning: Here is some more details.

When I walk up to another player or enemy npc I swing the punches facing them at close range and no damage at all. No errors in the output at all either. The structure of the entire script is as follow.

This script is under StarterPack

Player = game.Players.LocalPlayer
repeat wait() until Player.Character
Character = Player.Character
mouse = Player:GetMouse()

Enabled = true

– Click mouse to punch
mouse.Button1Down:connect(function()
for _, v in pairs(Player.Character:GetChildren()) do
if v:IsA(“Tool”) then return end
end
if Enabled == true then
script.Function:FireServer(“Combat”, Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-2).p)
end
end)

– Press Q to punch
game:GetService(“UserInputService”).InputBegan:connect(function(inputObject,gameProcessedEvent)
if gameProcessedEvent == true then return end
for _, v in pairs(Player.Character:GetChildren()) do
if v:IsA(“Tool”) then return end
end
if inputObject.KeyCode == Enum.KeyCode.Q then
if Enabled == true then
script.Function:FireServer(“Combat”, Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-2).p)
end
end
end)

Then inside this script an event labeled function, and inside that event is the script I originally posted. If all this helps any. Then inside StarterGUI I have a local script for the FX when hitting them. That goes as follow:

workspace.FX.ChildAdded:connect(function(Child)
if Child.Name == “CombatHit” then
local Mesh = Child:WaitForChild(“Mesh”)
local Info = TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out,0,false,0)
local Goals = {Scale=Vector3.new(7,7,7)}
local tween = game.GetService(“TweenService”):Create(Mesh,Info,Goals)
tween:Play()
local Mesh = Child:WaitForChild(“Mesh”)
local Info = TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out,0,false,0)
local Goals = {Transperency = 1}
local tween = game.GetService(“TweenService”):Create(Child,Info,Goals)
tween:Play()
end
end)

Maybe the FX part is making the punch not work? I am so lost. Thanks for any help.

I attempted some more debugging and removed the FX part of it completely and that didn’t solve the issue. It’s not even doing the sound effect or a “print” to console I just tried adding when they are being hit so I suspect maybe a proximity issue?

I assume it has something to do with the Region3 value but I’m not entirely sure…