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

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

Asked by 8 years ago

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"

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

1 answer

Log in to vote
0
Answered by
Im_Kritz 334 Moderation Voter
8 years ago

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

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

Full code:

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

Answer this question