Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Sword won't damage or play animations. Ideas?

i have a sword i am trying to make

note: i have a bool value "CanDamage" which the value is set to false

local script:

local CanAttack = true


    local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)

script.Parent.Equipped:Connect(function()
    
    idle:Play()    
end)


    local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)


script.Parent.Activated:Connect(function()
    
    if CanAttack == true then
        attack:Play()
        idle:Stop()
        CanAttack = false
        wait (1)
        attack:Stop()
        idle:Play()
        CanAttack= true
        script.Parent.CanDamage.Value = true
    end
end)

script:

script.Parent.blade.Touched:connect(function(p)
    if script.Parent.CanDamage.Value == true then
        script.Parent.CanDamage.Value = false
        p.Parent.Humanoid:TakeDamage(20)
    end
end)

the animation priorities are also right.

my sword wont play idle and attack animation, or attack, is something wrong in my script???

1 answer

Here is some help:

local CanAttack = true

local idle = script.Parent.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
local attack = script.Parent.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
 
script.Parent.Equipped:Connect(function()
    idle:Play()   
end)
 	 
script.Parent.Activated:Connect(function()

    if CanAttack == true then
	CanAttack = false
	script.Parent.CanAttack.Value = true
	idle:Stop()
	attack:Play()
	wait(1)
	attack:Stop()
        idle:Play()
        CanAttack= true
    end
end)

Hope this help! :)

4 comments

0

Hi! Unfortunately the script didn't seem to make a difference :c All of a sudden my sword scripts just stopped working and i'm finding myself so frustrated.

0

Is there any error?

0

well the original script gives an error that humanoid isnt a member of tool, how do i find local players humanoid?

0

oh wait, then you need to add another parent, since you are searching humanoid in the tool but the tool is a child of a player and the humanoid is also a child of the player

This discussion is preserved as it was. New answers, comments, and votes are closed.