Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Please help me get my punch to also hurt other players? (already hurts enemie NPCs)

Asked by 3 years ago

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!

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)
0
aim better DeceptiveCaster 3761 — 3y

Answer this question