I’m not that sure if making damage scripts for the hitbox is Extremely Complicated or not as I’m quite new but I just need to know how to make one for this and future reference.
All the damage scripts ive tried to make before always only damage My player and not the Dummy’s or Enemy Player
Script is for Cloning the Hitbox the rest Above it is just for Animations, Sound so most likely not useful.
To detect whether the player who is touching does not have the same name as the player, try getting the player first once they equip the tool. Then, use a variable “Event” to start a touch function for the hitbox.
Im not so sure if this code will work, but try this:
local Tool = script.Parent
local Event = nil
local Player
local Character
Tool.Equipped:Connect(function()
Character = Tool.Parent
Player = game.Players:GetPlayerFromCharacter(Character)
end)
Tool.Activated:Connect(function()
wait(0.25)
local Hitbox = RS.HitBox:Clone()
Hitbox.CFrame = HRP.CFrame * CFrame.new(0,0,-2)
Hitbox.Parent = workspace
Event = Hitbox.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr and plr.Name ~= Player.Name then -- checks if player touching does not have the same name as tool owner
plr.Character.Humanoid:TakeDamage(100)
end
end)
local weld = Instance.new("ManualWeld")
weld.Part0 = Hitbox
weld.Part1 = HRP
weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
weld.Parent = weld.Part0
wait(0.25)
Event = nil
Hitbox:Destroy()
end)
I tried this, put a couple prints in its arriving at Take Damage but is not doing anything to dummy nor me(Which is good) But I need the dummy to take damage
Hmm ok, so what i did in my code i checked whether it is a player, not a dummy. So if i were to change it, it’ll be like this:
Event = Hitbox.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum and hum.Parent.Name ~= Player.Name then -- checks if player touching does not have the same name as tool owner
hum:TakeDamage(100)
end
end)