#stun

1 messages · Page 1 of 1 (latest)

restive gulch
#

not sure how to do a stun for when the victim is touching the players hitbox.

local connection
connection = hitbox.Touched:Connect(function(hit)
local other = hit:FindFirstAncestorOfClass("Model"):WaitForChild("Humanoid")
if not other then
print("Not a humanoid")

    else
        if hit:FindFirstAncestorOfClass("Model") ~= char then
        hit:FindFirstAncestorOfClass("Model"):SetAttribute("Stunned", true)
        other.Health -= 10
        local bv = Instance.new("BodyVelocity")
        bv.Parent = other:FindFirstAncestorOfClass("Model"):WaitForChild("HumanoidRootPart")
        bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        bv.Velocity = hrp.CFrame.LookVector * force
        bv.P = 1250
        debris:AddItem(bv, 0.3)
        task.delay(1, function()
            
        end)
        connection:Disconnect()
    
        
        end
    end
end)



debris:AddItem(hitbox, 0.5)

hitbox.TouchEnded:Connect(function(hit)
    local other = hit:FindFirstAncestorOfClass("Model"):WaitForChild("Humanoid")
    if not other then
        print("Not a humanoid")

    else
        if hit:FindFirstAncestorOfClass("Model") ~= char then
            hit:FindFirstAncestorOfClass("Model"):SetAttribute("Stunned", false)
        end
    end
end)    

end)

brittle harness
#

local function stunOnTouch(hitbox, attackerChar, force)
local Debris = game:GetService("Debris")

local attackerHRP = attackerChar:FindFirstChild("HumanoidRootPart")
if not attackerHRP then return end

local connection
connection = hitbox.Touched:Connect(function(hit)
    local targetModel = hit:FindFirstAncestorOfClass("Model")
    if not targetModel or targetModel == attackerChar then return end

    local targetHumanoid = targetModel:FindFirstChildOfClass("Humanoid")
    local targetHRP = targetModel:FindFirstChild("HumanoidRootPart")
    if not targetHumanoid or not targetHRP then return end

    if targetModel:GetAttribute("Stunned") then return end

    targetModel:SetAttribute("Stunned", true)
    targetHumanoid:TakeDamage(10)

    local bv = Instance.new("BodyVelocity")
    bv.Velocity = attackerHRP.CFrame.LookVector * force
    bv.MaxForce = Vector3.new(1e5, 1e5, 1e5)
    bv.P = 1250
    bv.Parent = targetHRP
    Debris:AddItem(bv, 0.3)

    task.delay(1, function()
        if targetModel then
            targetModel:SetAttribute("Stunned", false)
        end
    end)

    connection:Disconnect()
end)

game:GetService("Debris"):AddItem(hitbox, 0.5)

end

-- ⬇️ Beispielhafter Aufruf (z. B. bei Angriff oder Fähigkeit)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
wait(3) -- Beispiel: Fähigkeit wird nach 3 Sekunden ausgelöst

    local hitbox = Instance.new("Part")
    hitbox.Size = Vector3.new(5, 5, 5)
    hitbox.CFrame = char:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(0, 0, -3)
    hitbox.Anchored = true
    hitbox.CanCollide = false
    hitbox.Transparency = 1
    hitbox.Parent = workspace

    stunOnTouch(hitbox, char, 50)
end)

end)
Is this working?