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

Why is my Sword not playing an Animation or taking Damage?

My Sword is supposed to do damage and play an animation. IT isn't doing either, but no error is playing. As you can see i added a print to just test it, and it is printing in output when i click.

I have two Scripts

This is a regular Script under the tool

script.Parent.blade.Touched:connect(function(p)


if script.Parent.CanDamage.Value == true then

if p.Parent:FindFirstChild("Humanoid") then
script.Parent.CanDamage.Value = false
p.Parent.Humanoid:TakeDamage(20)
wait(1)
script.Parent.CanDamage.Value = true
 end
end
end)

This is a Local Script under the tool. There is an animation "Attack" under the Local Script.

local CanDamage = true
vPlayer = game.Players.LocalPlayer
character = vPlayer.Character
humanoid = character:FindFirstChild('Humanoid') 

script.Parent.Activated:connect(function()

local Attack = humanoid:LoadAnimation(script.Attack)

 

if CanDamage == true then
print("hi")
Attack:Play()

CanDamage = false

wait(1)

Attack:Stop()

CanDamage = true

script.Parent.CanDamage.Value = true
end

end)

1 answer

In your server script, the value p should need to be put in a global variable to be read by the following line of code. This is done by adding this line after the function is called:

hitPart = p

Where you have

if p.Parent:FindFirstChild("Humanoid") then

and where you have

p.Parent.Humanoid:TakeDamage(20)

replace p with hitPart.

I your localScript, you might be trying to run R6 animations with an R15 rig, or vice versa. This is the only error I can think of for your localScript.

Both of these should work.

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