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

I am trying to that It will only harm the player If they touch a part that Isn't In a humanoid (?)

Asked by 1 year ago

Hello Developers!

I made this script, this script will force the user to do a drop kick, the problem Is that I want to add a system where If they kick a wall they will get harmed, the problem Is that It will harm the player If they touch a humanoid (Like a NPC or Player) due to the humanoid having parts

Script:

local NPC = script.Parent

if script.Enabled == true then
    local PlayerInventory = game:GetService("Players"):GetPlayerFromCharacter(NPC)
    if PlayerInventory then
        local Tools = PlayerInventory.Backpack:GetChildren()
        for _, Tool in ipairs(Tools) do
            if Tool:IsA("Tool") then
                Tool.Parent = game:GetService("ReplicatedStorage").FolderThatContainsWeapons
            end
        end
        NPC:WaitForChild("Drop Kick").Parent = game:GetService("ReplicatedStorage").FolderThatContainsWeapons
    end
    script.Swoosh:Play()
    local DropKick = NPC.Humanoid:WaitForChild("Animator"):LoadAnimation(script.Kick)
    DropKick:Play()
    NPC.HumanoidRootPart.Anchored = true
    local TweenPropteries = {
        CFrame = NPC.HumanoidRootPart.CFrame + (NPC.HumanoidRootPart.CFrame.LookVector*35)
    }
    local Tweeninfo = TweenInfo.new(
        1,
        Enum.EasingStyle.Cubic,
        Enum.EasingDirection.InOut,
        0,
        false,
        0
    )
    local Tween = game:GetService("TweenService"):Create(NPC.HumanoidRootPart,Tweeninfo,TweenPropteries)
    Tween:Play()
    local Hits = {}
    NPC["Left Leg"].Touched:Connect(function(hit)
        local Character = hit:FindFirstAncestorWhichIsA("Model")
        local Humanoid = Character and Character:FindFirstChildWhichIsA("Humanoid")
        local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if Player then
            local player1 = game.Players:GetPlayerFromCharacter(hit.Parent)
            local player2 = game.Players:GetPlayerFromCharacter(NPC)

            if (player1 ~= nil) and (player2 ~= nil) then
                local humanoid = (player1.Character or player1.CharacterAdded:Wait()):FindFirstChildWhichIsA("Humanoid")

                if (player1.TeamColor ~= player2.TeamColor) then
                    if (humanoid ~= nil) and (humanoid.Health >= 0) and not Hits[Character] then
                        Hits[Character] = true
                        script.Contact:Play()
                        Humanoid:TakeDamage(30)
                        local RagdollScript = script.Ragdoll:Clone()
                        game:GetService("Debris"):AddItem(RagdollScript,2)
                        RagdollScript.Parent = humanoid.Parent
                        RagdollScript.Enabled = true
                        local VectorForce = Instance.new("VectorForce",humanoid.Parent.Torso)
                        local Attachment = Instance.new("Attachment",humanoid.Parent.Torso)
                        VectorForce.Attachment0 = Attachment
                        VectorForce.Force = Vector3.new(0,300,6000)
                        VectorForce.ApplyAtCenterOfMass = true
                        game:GetService("Debris"):AddItem(VectorForce,0.5)
                        game:GetService("Debris"):AddItem(Attachment,0.5)
                        wait(1)
                        Hits[Character] = false
                    end
                    if not player1.Team and (humanoid ~= nil) and (humanoid.Health >= 0) and not Hits[Character] then
                        Hits[Character] = true
                        local RagdollScript = script.Ragdoll:Clone()
                        game:GetService("Debris"):AddItem(RagdollScript,2)
                        RagdollScript.Parent = humanoid.Parent
                        RagdollScript.Enabled = true
                        script.Contact:Play()
                        Humanoid:TakeDamage(30)
                        local VectorForce = Instance.new("VectorForce",humanoid.Parent.Torso)
                        local Attachment = Instance.new("Attachment",humanoid.Parent.Torso)
                        VectorForce.Attachment0 = Attachment
                        VectorForce.Force = Vector3.new(0,300,6000)
                        VectorForce.ApplyAtCenterOfMass = true
                        game:GetService("Debris"):AddItem(VectorForce,0.5)
                        game:GetService("Debris"):AddItem(Attachment,0.5)
                        wait(1)
                        Hits[Character] = false
                    end
                end
            end
        elseif not Player then
            local Character = hit:FindFirstAncestorWhichIsA("Model")
            local Humanoid = Character and Character:FindFirstChildWhichIsA("Humanoid")
            if Humanoid and Humanoid.Health >= 0 and not Hits[Character] then
                Hits[Character] = true
                script.Contact:Play()
                Humanoid:TakeDamage(30)
                local RagdollScript = script.Ragdoll:Clone()
                game:GetService("Debris"):AddItem(RagdollScript,2)
                RagdollScript.Parent = Humanoid.Parent
                RagdollScript.Enabled = true
                local VectorForce = Instance.new("VectorForce",Humanoid.Parent.Torso)
                local Attachment = Instance.new("Attachment",Humanoid.Parent.Torso)
                VectorForce.Attachment0 = Attachment
                VectorForce.Force = Vector3.new(0,300,6000)
                VectorForce.ApplyAtCenterOfMass = true
                game:GetService("Debris"):AddItem(VectorForce,0.5)
                game:GetService("Debris"):AddItem(Attachment,0.5)
                wait(1)
                Hits[Character] = false
            end
        end
    end)
    NPC["Left Leg"].Touched:Connect(function(Hit)
        if Hit:IsA("BasePart") and not Hit.Parent.Humanoid then
            local FailHit = script.Fail:Clone()
            FailHit.Parent = NPC
            FailHit.Enabled = true
            NPC.HumanoidRootPart.Anchored = false
            DropKick:Stop()
            script:Destroy()
        end
    end)
    wait(0.3)
    NPC.HumanoidRootPart.Anchored = false
    wait(1)
    DropKick:Stop()
    local GetUp = NPC.Humanoid:WaitForChild("Animator"):LoadAnimation(script.GetUp)
    GetUp:Play()
    wait(0.1)
    NPC.HumanoidRootPart.Anchored = false
    local Tools = game:GetService("ReplicatedStorage").FolderThatContainsWeapons:GetChildren()
    for _, Tool in ipairs(Tools) do
        if Tool:IsA("Tool") then
            Tool.Parent = NPC
        end
    end
    NPC.Humanoid:UnequipTools()
    script:Destroy()
end
0
Are you sure that damage is not being dealt because of touching the floor? brandons2005 87 — 1y
0
Wydm imnotaguest1121 362 — 1y
0
Wydm imnotaguest1121 362 — 1y
0
Maybe try :FindFirstChild to see if there is a humanoid inside of the parent part that the dropkick hit LeoPlaysGames_RBX 26 — 1y

Answer this question