Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I reach the backpack of an enemy that is being punched?

at line 3 I want to reach the backpack because there is a value named defe and I need that value so I can divide "d" and "Defense"

	if Part.Parent:FindFirstChild("Humanoid")~= nil then
			local attk = script.Parent.Parent.mLevel.Value
local Defense = Part.Parent.Parent.Parent.Backpack:WaitForChild("defe").Value
local d = attk/Defense*7+2
			local dmg = d/Defense
Part.Parent.Humanoid:TakeDamage(dmg)

1 answer

✓ Accepted answer

To reach the backpack you need to get the player, not the character. To define the player, I recommend you use :GetPlayerFromCharacter()

local player = game:GetService('Players'):GetPlayerFromCharacter(Part.Parent)

Full code:

    if Part.Parent:FindFirstChild("Humanoid")~= nil then
            local attk = script.Parent.Parent.mLevel.Value
local player = game:GetService('Players'):GetPlayerFromCharacter(Part.Parent)
local Defense = player.Backpack:WaitForChild("defe").Value
local d = attk/Defense*7+2
            local dmg = d/Defense
Part.Parent.Humanoid:TakeDamage(dmg)

This discussion is preserved as it was. New answers, comments, and votes are closed.