-
What do you want to achieve?
Make a sword that can damage another player. -
What is the issue?
The sword sometimes cannot damage a player.
-
What solutions have you tried so far?
I added more DmgPoints but nothing happened.
The scripts i used:
CLIENT (Local script)
local Tool = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()
local Hit = script.Parent:WaitForChild("Hit")
function isEquipped()
if Tool.Parent:FindFirstChild("Humanoid") then
return true else return false
end
end
Mouse.Button1Down:Connect(function()
if not isEquipped() then return end
Hit:FireServer()
end)
SERVER (SCRIPT)
local Tool = script.Parent
local Handle = Tool.Handle
local Anims = Tool.Anims
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(Tool.Hitbox)
local de = false
local canHit = false
config = {
Damage = 20,
AttackTime = .1,
Cooldown = .3
}
Hitbox.OnHit:Connect(function(hit, humanoid)
if canHit == false then return end
canHit = false
if humanoid.Parent ~= script.Parent.Parent then
humanoid:TakeDamage(config.Damage)
print("hit")
local character = humanoid.Parent
local Knockback = Instance.new("BodyVelocity")
Knockback.P = math.huge
Knockback.Parent = character:FindFirstChild("HumanoidRootPart")
Knockback.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
Knockback.Velocity = character:FindFirstChild("HumanoidRootPart").CFrame.lookVector * -7
game:GetService("Debris"):AddItem(Knockback, .3)
task.wait(.35)
end
canHit = true
end)
script.Parent.Hit.OnServerEvent:Connect(function(Player)
if de == false then
de = true
local Humanoid = Player.Character.Humanoid
local AnimationsList = Anims:GetChildren()
local Selected = Humanoid:LoadAnimation(AnimationsList[math.random(1, #AnimationsList)])
Selected:Play()
Hitbox:HitStart()
wait(config.AttackTime)
canHit = true
Humanoid.WalkSpeed = 1
wait(config.Cooldown)
Humanoid.WalkSpeed = 16
Hitbox:HitStop()
canHit = false
de = false
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.