How to make a reflect tree that reflect damage

how to make a reflect tree that reflect damage

3 Likes

Baically
Humanoid.Health = Humanoid.Health - TreeDamage

Too hard give you normal answer when your topic just 1 sentence.

1 Like

should i add humanoid to the tree? and use this?

local connection
connection = humanoid.HealthChanged:Connect(function()

1 Like

I can’t say this to you, bc I don’t fully know what you want.
Humanoid - player’s humanoid which trying damage tree. If you want make tree breakable, you can use Number or Int values, and add
TreeHealth = TreeHealth - TreeDamage

1 Like

i want a tree that if player damage it player get the damage that deal to the tree

1 Like

Humanoid.Health = Humanoid.Health - TreeDamage
TreeHealth = TreeHealth - TreeDamage

Humanoid - player’s humanoid
TreeHealth - Number or Int value.
TreeDamage - Damage, which somehow was dealed to tree.

1 Like

how to make the person who deal damage to tree get damage? how to track them?

1 Like

You mean getting how much damage the player has done to the tree?

Player hit tree, tree gets damaged, how much damage done to tree by player(information) sent to player???

Is this what you mean??

1 Like

I dont know what kind of a system you are using but you can just put something to detect a hit, get the damage made and just apply it to the player.

yeah that is what i mean , i want to achieve that

1 Like

I think this is what OP is looking for:

  • The player will attack a tree, and the tree will take a specific amount of damage
  • The damage of the tree will then be sent to the client in the form of a GUI when their mouse hovers over it (for example) This way the client can tell how much damage they need to do to the tree to break it.

Is that right, @MadionChooi?

2 Likes

i want to make it like ARK use hand to break tree , like if u hit the tree u take damage and couple of time the tree destroy

1 Like

So you want the player to be hurt by damaging the tree with their fists, but in turn also damage the tree slightly?

2 Likes

Adding onto this point I just said, it appears this is how you want it to work;

This type of thing seems pretty easy to make. I suppose I could hop in studio and help you out.

Just to confirm though, does this seem right?

1 Like

ik the script to get wood and thatch i use

local get = math.random(1, 3)
if get == 1 then
local wood = script.Wood:Clone()
wood.Parent = bag


but idk how to let them take damage like tree hp - 5 , playerhp - 5

2 Likes

The humanoid has a function called Humanoid:TakeDamage(Number). The Number is the amount of damage that would be taken against the Humanoid.

If you’re making a tree, there would usually be a NumberValue inside it that determines it’s health.

You can do basic math to lower it when the player punches it.

TreeHealth.Value = TreeHealth.Value - 5

Then you could listen to the TreeHealth NumberValue and get rid of the tree when it’s destroyed.

TreeHealth.Changed:Connect(function()
    if TreeHealth.Value <= 0 then
    -- destroy the tree
    end
end)
2 Likes

btw how to detect who is the one breaking the tree?

1 Like

If you want to make the tree detect when the player has hit it, you can use the .Touched event to listen for any interaction on the trees parts.

From there you can fetch the player by doing this:

TreePart.Touched:Connect(function(HitPart)
    if HitPart.Parent:FindFirstChildWhichIsA("Humanoid") then
        local Character = HitPart.Parent
        local Player = game.Players:GetPlayerFromCharacter(Character)
        -- This is technically where you would apply damage to the tree and player.
        -- For example,
        -- Humanoid:TakeDamage(5)
        -- TreeValue.Value = TreeValue.Value - 5
    end
end)

You would need to implement a debounce to prevent it from firing too many times.

2 Likes

What if I use if No Weapon = true then humanoid take damage tree damage 5 else humanoid didn’t take damage tree damage 10

1 Like

You could do that if you would like. Personally I would use a table of the tools in your game, and what damages they do. You could also create a “flag” in the table which determines whether or not the item will hurt the player or not.

local TableOfTools = {
    ["Hand"] = {
        Damage = 5,
        PlayerTakeDamage = true
    },

    ["Stone Thatch"] = {
        Damage = 10,
        PlayerTakeDamage = false
    }
}

If you intend on different tools doing different damage values to the player, and not always 5, you could specify the PlayerDamage under the table of tools

Also one more thing, you could do this to see if the Tool is actually a tool that can attack the tree:

if table.find(TableOfTools, HitPart.Parent.Name) then
    -- Does the tool exist? If it does, get the position of it in the table
    -- We're assuming the script is utilizing the Tools Handle, and not a Characters BodyPart
    local FoundTool = TableOfTools[HitPart.Parent.Name]
    local DamageToTake = FoundTool.Damage

    if FoundTool.PlayerTakeDamage == true then
        Humanoid:TakeDamage(5)
        TreeValue.Value = TreeValue.Value - DamageToTake
    else
        TreeValue.Value = TreeValue.Value - DamageToTake
    end
end

You would need to specify the Players Humanoid for the damage to apply or it will throw an error; However I believe I’ve already explained how to get the Character and the Humanoid in earlier scripts

1 Like