-
What do you want to achieve? I’m trying to basically make my own version of the birch tree from Item Asylum, and I need it to kill any humanoid it touches when you attack with it.
-
What is the issue? I can’t figure out how to make the tree kill humanoids it touches.
-
What solutions have you tried so far? I’ve tried to search the devforum and script it myself, but I can’t figure out how to, since I’ve never really done anything relating to fighting.
Would appreciate anyone who can help me with this. Thanks.
I need more information about what are you trying to achieve as I’ve not heard of Asylum. Are you trying to make a tool handle and when the tool handle touches a humanoid it will kill them?
Basically the tool is meant to have a hitbox, and if a humanoid touches the hitbox while the tool is being used, that humanoid is killed. (I say humanoid because I want all humanoids to be killed by it, not just players.)
This is fairly simple to do.
This should be done in a server script by the way:
local tool = script.Parent
local hitbox = tool:WaitForChild("Hitbox")
local activated = false
local isTouched = false
local damage = 36
tool.Activated:Connect(function()
if not cooldown then
activated = true
task.wait(3)
activated = false
end
end)
hitbox.Touched:Connect(function(hit)
if activated and not isTouched then
local character = hit.Parent
if character:FindFirstChild("Humanoid") then
humanoid: Humanoid = character.Humanoid
humanoid:TakeDamage(damage)
isTouched = true
end
end
end)
hitbox.TouchEnded:Connect(function(hit)
if isTouched then
local character = hit.Parent
if character:FindFirstChild("Humanoid") then
isTouched = false
end
end
end)
I’ve also included a cooldown for the tool, but it is not necessary if you do not want it. I would highly recommend it, though. It is to prevent it from damaging the humanoid a bunch of times in a second.
1 Like
Add a hitbox part inside of your handle and size it to your likings, then add a boolean value to the tool named “Activated” and a Script inside the hitbox:
-- Script inside the tool:
local tool = script.Parent
local damageFor = .5
tool.Activated:Connect(function()
tool.Activated.Value = true
wait(damageFor)
tool.Activated.Value = false
end)
-- Script inside the hitbox:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and script.Parent.Parent.Activated.Value == true then
hit.Parent:FindFirstChild("Humanoid").Health = 0
end
end)
This is just my fair guess tho since I don’t really work with tools all that often.
Edit: You should probably go with Amora’s code since it’s way better.
To make your own version of the birch tree from Item Asylum that kills any humanoid it touches, you can use a simple script attached to the tree’s root part.
Here’s an example script you can use:
local rootPart = script.Parent
rootPart.Touched:Connect(function(part)
local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid:TakeDamage(humanoid.MaxHealth)
end
end)
This script listens for the Touched event on the tree’s root part. When the tree collides with another object, the script checks if the object has a humanoid in its parent hierarchy using the FindFirstChildOfClass method. If it does, the script calls the TakeDamage method on the humanoid, which sets the humanoid’s Health to 0 and triggers its death.
You can adjust the amount of damage the tree inflicts by changing the argument passed to the TakeDamage method.
Note that this script assumes the tree is not meant to be held by a player. If you want to allow players to use the tree as a weapon, you’ll need to add additional logic to check when the player attacks with the tree and then trigger the damage.