I’ve been trying to get humanoid from touched event when i clealry defined __HIT.Parent, which very much should clearly get the parent of humanoidrootpart, however it does not seem to work for whatever reason.
__WOODS.Touched:Connect(function(__HIT)
if __HIT:IsA("BasePart") and __HIT.Name ~= "Wood" and not __DEBO then
__DEBO = true
local __CHAR = __HIT.Parent
local __HUM = __CHAR:WaitForChild("Humanoid")
local BodyVelocity = Instance.new("BodyVelocity", __CHAR.Torso)
BodyVelocity.Velocity = Vector3.new(3,50,3) * 10
game.Debris:AddItem(BodyVelocity, 1)
__HUM:TakeDamage(math.random(20,40))
__DEBO = false
end
end)
My issue here is it gets Right Leg “humanoid” instead of the actual humanoid in the character model.
__WOODS.Touched:Connect(function(__HIT)
if __HIT.Name == "Wood" or __DEBO then
return
end
local __CHAR = __HIT.Parent
local __HUM = __CHAR:FindFirstChildWhichIsA("Humanoid")
if not __HUM then
return
end
__DEBO = true
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.Velocity = Vector3.new(3, 50, 3) * 10
BodyVelocity.Parent = __CHAR.Torso
task.delay(1, function()
BodyVelocity:Destroy()
end)
__HUM:TakeDamage(Random.new():NextInteger(20, 40))
__DEBO = false
end)
Your current code is a terrible way to do it. Here’s some new code.
Woods.Touched:Connect(function(Hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
if Hit.Parent:FindFirstChildOfClass("Humanoid") and Player and Hit.Parent:FindFirstChild("HumanoidRootPart") and not db then
db = true
local char = Hit.Parent
local hum = char:FindFirstChild("Humanoid")
local BodyVelocity = Instance.new("BodyVelocity", char.HumanoidRootPart)
BodyVelocity.Velocity = Vector3.new(3,50,3) * 10
game:GetService("Debris"):AddItem(BodyVelocity, 1)
hum:TakeDamage(math.random(20,40))
db = false
end
end)
Also, I don’t understand why you put __ before everything… it makes it very hard to read…