#Problem with Knockback Module using ApplyImpulse ; General Question about NetworkOwnerShip of Parts

1 messages · Page 1 of 1 (latest)

tidal garden
#

I have one question and a problem

My question is:
When does a Parts NetworkOwnerShip change from nil to a Players NetworkOwnerShip and when does it change back?

My Problem is this Module Script:

local ApplyKnockback = {}
local KnockbackRemoteEvent = game.ReplicatedStorage.RemoteEvents.KnockbackRemoteEvent

function ApplyKnockback(EnemyHRP, AttackerHRP, UpwardsArc, KnockbackForce, TypeOfDirection, MakeEnemyFaceAttacker)
    local Direction = nil
    local EnemyMass = EnemyHRP.AssemblyMass
    local LookVector = AttackerHRP.CFrame.LookVector
    local EnemyPlayer = EnemyHRP:GetNetworkOwner()
    print("Knockback ||| Attacker: ".. AttackerHRP.Parent.Name .. ". and Victim: " .. EnemyHRP.Parent.Name)
    if not KnockbackForce then return end
    if not UpwardsArc then UpwardsArc = 0 end
        if TypeOfDirection == "Away" then
        Direction = (EnemyHRP.Position - AttackerHRP.Position + Vector3.new(0, UpwardsArc, 0)).Unit
    end
    if TypeOfDirection == "Pull" then
        Direction = (AttackerHRP.Position - EnemyHRP.Position + Vector3.new(0, UpwardsArc, 0)).Unit
    end
    if TypeOfDirection == "LookVector" then
        Direction = Vector3.new(LookVector.X, UpwardsArc, LookVector.Z).Unit
    end
    if MakeEnemyFaceAttacker then
        local LookDirection = Vector3.new(LookVector.X, 0, LookVector.Z).Unit
        EnemyHRP.CFrame = CFrame.lookAt(EnemyHRP.Position, AttackerHRP.Position - LookDirection)
    end
    if EnemyPlayer then
        print("HumanoidRootPartOwner: " .. EnemyHRP.Parent.Name ..  ". and NetworkOwner: " .. EnemyPlayer.Name)
        KnockbackRemoteEvent:FireClient(EnemyPlayer, Direction, EnemyMass, KnockbackForce)
        print("Impulsing a player")
    else
        EnemyHRP:ApplyImpulse(Direction * EnemyMass * KnockbackForce)
    end
end

return ApplyKnockback
#

To go into further detail:
For some reason, The NetworkOwner of the EnemyHRP sometimes is the Attacker. This leads to the attacker getting Impulsed/Knockbacked.
So I was wonder how exactly Roblox handles NetworkOwnerShip of Parts.

#

This the Script in which I use the Module shown above. It is located in ServerScriptService

#

And This is the BlockBreakHandler which is called at the end of the HandleNormalBlock function.

local BlockBreakBE = game:GetService("ReplicatedStorage").BindableEvents.BlockBreakBindableEvent

BlockBreakBE.Event:Connect(function(BlockBreakGui, EnemyChar)
    for i = 1, 50 do
        task.wait(0.1)
        BlockBreakGui.BlockLabel.ImageTransparency = BlockBreakGui.BlockLabel.ImageTransparency + 0.030
    end
    BlockBreakGui.Enabled = false
    EnemyChar.Humanoid.WalkSpeed = 18
    EnemyChar:SetAttribute("BlockingState", "off")
    BlockBreakGui.BlockLabel.ImageTransparency = 0.18
end)```
vivid heronBOT
#

studio** You are now Level 11! **studio

tidal garden
#

If you think there is a problem with something else like the Block System which is not shown or the LocalScripts that handles the Input then tell me and I will send them as well

tidal garden
#

I fixed the problem

#

This is the fixed code if anyone is interested

function ApplyKnockback(EnemyHRP, AttackerHRP, UpwardsArc, KnockbackForce, TypeOfDirection, MakeEnemyFaceAttacker)
    local Direction = nil
    local EnemyMass = EnemyHRP.AssemblyMass
    local LookVector = AttackerHRP.CFrame.LookVector
    if not KnockbackForce then return end
    if not UpwardsArc then UpwardsArc = 0 end
    if TypeOfDirection == "Away" then
        Direction = (EnemyHRP.Position - AttackerHRP.Position + Vector3.new(0, UpwardsArc, 0)).Unit
    end
    if TypeOfDirection == "Pull" then
        Direction = (AttackerHRP.Position - EnemyHRP.Position + Vector3.new(0, UpwardsArc, 0)).Unit
    end
    if TypeOfDirection == "LookVector" then
        Direction = Vector3.new(LookVector.X, UpwardsArc, LookVector.Z).Unit
    end
    if MakeEnemyFaceAttacker then
        local LookDirection = Vector3.new(LookVector.X, 0, LookVector.Z).Unit
        EnemyHRP.CFrame = CFrame.lookAt(EnemyHRP.Position, AttackerHRP.Position - LookDirection)
    end
    if EnemyHRP:GetAttribute("PlayerUserId") then
        local EnemyPlayer = game.Players:GetPlayerFromCharacter(EnemyHRP)
        KnockbackRemoteEvent:FireClient(EnemyPlayer, Direction, EnemyMass, KnockbackForce)
        print("Impulsing a player")
    else
        EnemyHRP:ApplyImpulse(Direction * EnemyMass * KnockbackForce)
    end
end

return ApplyKnockback
#

Instead of relaying on Network ownership i just give every player an attribute

#

and check if that player has an attribute

#

About the Network ownership:

#

I just did some research

#

and there seems to be a way to show which part belongs to what:

#

This is how you show which part belongs to which Network Owner

#

Im guessing White is nil
Im not quite sure what red is
but im pretty sure green means that the client owns the part

robust ginkgo
#

you can show it with this toggle

robust ginkgo