I am scripting a quick little hitbox script and I tested it out and it does not do damage to other players
local db = false
local attackDB = false
game.ReplicatedStorage.M1RE.OnServerEvent:Connect(function(plr)
local SwordM1Track = plr.Character.Humanoid:LoadAnimation(plr.Character.Sword.SwordFunction.SwordM1)
local SwordValues = require(script.SwordValues)
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local HitBox = hrp:WaitForChild("HitBox")
if db then return end
if plr and not db then
db = true
SwordM1Track:Play()
HitBox.Size = Vector3.new(10,10,10)
HitBox.CanTouch = true
HitBox.Touched:Connect(function(hit)
local attackPlr = game.Players:GetPlayerFromCharacter(hit.Parent)
for i,v in game.Workspace:GetChildren() do
if v == plr then
continue
elseif attackPlr then
attackPlr.Character:WaitForChild("Humanoid").Health = 0
end
end
end)
task.wait(SwordValues.AttackCooldown)
SwordM1Track:Stop()
HitBox.Size = Vector3.new(7,8,5)
HitBox.CanTouch = false
db = false
attackDB = false
end
end)
The first major issue I see is that you’re comparing the player’s character to the player itself in the if statement “if v == plr then”. To fix this, just change the if statement to “if v.Name == plr.Name”.
please refrain from using WaitForChild inside remote event scripts, because if that child doesn’t exist, the code will yield and it won’t stop running, essentially exploiters can abuse this and fire the remote event multiple times and crash the server
second of all, why are you loading AND playing the animation on the server? why not just do it on the client?
third of all, why do you check if db == false in the if plr and not db then?
the function will stop if db is true the moment it hits the if db then return end line
fourth, instead of having a .Touched event, just use a for loop, because i assume this script runs each time the player swings a weapon
for _,v in Hitbox do
local otherPlayer = game.Players:GetPlayerFromCharacter(v.Parent)
if v.Parent:FindFirstChild("Humanoid") and otherPlayer then
local enemy = v.Parent:FindFirstChild("Humanoid")
enemy:TakeDamage(100) -- or enemy.Health = 0
end
end
local Size = Vector.new(10,10,10)
local CFrame = player.Character:FindFirstChild("HumanoidRootPart").CFrame -- change this if you want to
local Hitbox = workspace:GetPartBoundsInBox(CFrame, Size)
for _,v in Hitbox do
local otherPlayer = game.Players:GetPlayerFromCharacter(v.Parent)
if v.Parent:FindFirstChild("Humanoid") and otherPlayer then
local enemy = v.Parent:FindFirstChild("Humanoid")
enemy:TakeDamage(100) -- or enemy.Health = 0
end
end
Have you tried using the debugging tool? You can find information on it here.
Though the issue may have to do with the type of hitbox you’re using. Touched() is unreliable and bad at detecting anything already inside the area. Instead, you should use a magnitude hitbox. I have a guide on how to use them here.