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 |
3 | local Defense = Part.Parent.Parent.Parent.Backpack:WaitForChild( "defe" ).Value |
4 | local d = attk/Defense* 7 + 2 |
5 | local dmg = d/Defense |
6 | Part.Parent.Humanoid:TakeDamage(dmg) |
To reach the backpack you need to get the player, not the character. To define the player, I recommend you use :GetPlayerFromCharacter()
1 | local 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 |
3 | local player = game:GetService( 'Players' ):GetPlayerFromCharacter(Part.Parent) |
4 | local Defense = player.Backpack:WaitForChild( "defe" ).Value |
5 | local d = attk/Defense* 7 + 2 |
6 | local dmg = d/Defense |
7 | Part.Parent.Humanoid:TakeDamage(dmg) |