It’s kinda weird script to damage player but
Replace this script
HitBox.Touched:Connect(function(hit)
local hum = player.Character.FindFirstChildOfClass("Humanoid") -- you forgot ":" at here and also it's pointless to find humanoid if you won't do anything to do because of the if then argument below
if hum and hum.Parent.Name ~= player.Name then -- what? You preventing player to take damage
hum:TakeDamage(1000)
HitBox:Destroy()
end
end)
To this script :
HitBox.Touched:Connect(function(object)
if object:FindFirstAncestorWhichIsA("Model") and object:FindFirstAncestorWhichIsA("Model"):FindFirstChildOfClass("Humanoid") then -- find the model of that object and find humanoid too
local character = object:FindFirstAncestorWhichIsA("Model") -- character
local Chum = object:FindFirstAncestorWhichIsA("Model"):FindFirstChildOfClass("Humanoid") -- humanoid
if Chum and hum.Parent.Name == player.Name then -- detect if humanoid is there and character has the right name
hum:TakeDamage(1000)
HitBox:Destroy()
end
end
end)
Tell me if there’s any errors occur within my script!
Still doesn’t damage the dummy
Oh yeah, i forgot that i shouldn’t use findfirstchildofclass
replace the entire script i provided for you above with this new one :
HitBox.Touched:Connect(function(object)
if object:FindFirstAncestorWhichIsA("Model") and object:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") then -- find the model of that object and find humanoid too
local character = object:FindFirstAncestorWhichIsA("Model") -- character
local Chum = object:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") -- humanoid
if Chum and Character.Name ~= player.Name then
hum:TakeDamage(1000)
HitBox:Destroy()
end
end
end)
This definitely would work
maybe make the touched event happen before the hitbox is destroyed…
Also, I’m confused what the goal is with the touched event.
Ok the hitbox works but it only damages me
HitBox.Touched:Connect(function(object)
if object:FindFirstAncestorWhichIsA("Model") and object:FindFirstAncestorWhichIsA("Model").Name ~= player.Name and object:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") then -- find the model of that object and find humanoid too
local character = object:FindFirstAncestorWhichIsA("Model") -- character
local Chum = object:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") -- humanoid
if Chum and character.Name ~= player.Name then
Chum:TakeDamage(1000)
HitBox:Destroy()
end
end
end)
Maybe? i don’t really know what cause it to not working tho
Thank you for helping me figure it out cause i’ve been stuck on it for 2 hours
Also my goal was just to have the npc or another player be damaged whenever a player punches
I would’ve made it to where if a player is under leveled they can’t get damaged by higher levels but i’m still a beginner and don’t really know how i would go about coding that
You’d need a int value that provide their level, if a character’s level is lower than the target level, the damage won’t happen
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.