Hello fellow developers ! I saw this YouTube tutorial about making a double handed sword in roblox by anobot ( ROBLOX Tutorials I How to Make a Sword - YouTube ). I don’t know why but when I made the complete sword the animations don’t work at all which are that the dual wielding and the swings don’t work. Can anyone help me fix this. All help will be appreciated.
btw this is the main code of the sword
-- Variables
local db = false
local canHit = false
local randomSlash = 1
local idle
local slash
-- Configure
local con = {
trailEnabled = true;
bloodEffects = true
}
-- Player Equip
script.Parent.Equipped:Connect(function()
script.Parent.Handle.Equip:Play()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not idle then idle = humanoid:LoadAnimation(script.Equip) end
idle:Play()
end)
-- The sword slashes
script.Parent.Activated:Connect(function()
if not db then
db = true
if con.trailEnabled == true then
script.Parent.Handle.Trail.Enabled = true
end
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not slash then
if randomSlash == 1 then
slash = humanoid:LoadAnimation(script.Slash1)
randomSlash = randomSlash + 1
elseif randomSlash == 2 then
slash = humanoid:LoadAnimation(script.Slash2)
randomSlash = randomSlash - 1
end
end
slash:Play()
wait(.2)
script.Parent.Handle.Slash:Play()
wait(.8)
if slash then
slash:Stop()
slash = nil
end
script.Parent.Handle.Trail.Enabled = false
db = false
end
end)
-- If the sword slash, the damage meets
script.Parent.Handle.Touched:Connect(function(hit)
if db then
if not canHit then
canHit = true
local effect = script.Parent.Handle.Effect:Clone()
if hit.Parent:FindFirstChild("Humanoid") then
local hitSFX = Instance.new("Sound",hit.Parent.Head); hitSFX.SoundId = "rbxassetid://566593606"; hitSFX:Play()
hit.Parent.Humanoid:TakeDamage(10)
if con.bloodEffects == true then
effect.Parent = hit.Parent.HumanoidRootPart
effect.Enabled = true
end
end
wait(1)
effect:Destroy()
canHit = false
end
end
end)
-- Stops Everything when we unequip
script.Parent.Unequipped:Connect(function()
if idle then idle:Stop() end
if slash then slash:Stop() end
end)