What do you want to achieve?
I want a sword that works with animation
What is the issue?
The animations that i made work perfectly fine but the sword isn’t dealing damage
What solutions have you tried so far?
I’ve looked into the Dev forum and tried different methods but neither of them worked
Here is my code
attack.OnServerEvent:Connect(function(plr)
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local anim = Instance.new("Animation", plr)
anim.AnimationId = "rbxassetid://10401972276"
local animtrack = animator:LoadAnimation(anim)
animtrack:Play()
repeat wait() until animtrack.IsPlaying
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid").Health -= 50
end
end)
hitbox.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = humanoid.Health - 50
end
end)
Slightly hacky solution, but what you could do is weld an invisible part into the sword mesh/model and then put this script in the part:
local sword = script.Parent
local function dealDamage(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = humanoid.Health - 50 --or however many integers
end
end)
sword.Touched:Connect(dealDamage)