Blade isn't damaging when activated

Hello !
I’m doing a blade for SCP-076-2 and I got 2 script :

Local script :

local CanAttack = true

script.Parent.Activated:connect(function()
	local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
	local chill = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
	
	if CanAttack == true then
		attack:Play()
		script.Parent.Handle.AttackSound:Play()
		CanAttack = false
		wait(1)
		CanAttack = true
		script.Parent.CanDamage.Value = true
		print("Changed value")
		chill:Play()
	end
end)

Script that handle damage part : (Normal script)

local Teams = game:GetService("Teams")

script.Parent.Handle.Touched:Connect(function(p)
	if script.Parent.CanDamage.Value == true then
     	script.Parent.CanDamage.Value = false
		p.Parent.Humanoid:TakeDamage(500)
		print('Died of severe slashes across the chest.')
		script.Parent.Handle.Dead:Play()
	end
end)

Value is correctly changed cuz of the print function. The problem come from the damage part, it doesn’t damage the humanoid, and play the sound after.
– Edit –
Just want to precise that both of script are locatd in the tool ( not in handle ) and that 2 animations are stored inside the local script)

You aren’t implementing any sanity checks for your ServerScript, it’s just assuming that it’s trying to find a Humanoid but keeps resulting as a nil value

Try this:

script.Parent.Handle.Touched:Connect(function(p)
	if script.Parent.CanDamage.Value == true and p.Parent:FindFirstChild("Humanoid") then
        local Target = p.Parent

     	script.Parent.CanDamage.Value = false
		Target.Humanoid:TakeDamage(500)
		print('Died of severe slashes across the chest.')
		script.Parent.Handle.Dead:Play()
	end
end)

Also couple side notes:

  • Are you wanting the play the animations for the Client only? Cause it’ll only be visible to your screen and not everyone else’s

  • You could easily do this with 1 Server Script, there’s no need to use both a Local & Server

It doesn’t seems to work, in the output I have no error, and a print of the Local script

I moved the local script into the script and it fixed it for some reasons…

Is the animation playing? It could be that you are trying to load the animations every time the sword is activated rather that in a script in StarterPlayer.StarterCharacterScripts.

Alright, glad it worked! It could have been an issue with the hierarchy. For example: you said Script.Parent.Parent but it could have been Script.Parent.Parent.Parent

I think you have to use Humanoid.Animator:LoadAnimation() to load it.

Nah both script were at the same place, I tried to move thr print function in the script, and it seems that it came from the script.Parent.CanDamage.Value statement.
the script doesn’t detect the value change, perhaps

Loading animations directly on to humanoid is deprecated and not recommended but it still works.

1 Like

Ok here’s what I’d do then:

Encase your script into just 1 entire Server Script, that way it’s easier to organize & maintain properly

local Tool = script.Parent
local CanAttack = true
local Character
local Animator

Tool.Activated:Connect(function()
    local AttackAnim = Animator:LoadAnimation(script.Attack)
    local ChillAnim = Animator:LoadAnimation(script.Idle)

    if CanAttack == true then
        Tool.Handle.Touched:Connect(function(Hit)
            if Hit.Parent:FindFirstChild("Humanoid") then
                Hit.Parent.Humanoid:TakeDamage(500)
                print("OW")
                CanAttack = false
                AttackAnim:Play()
                Tool.Handle.AttackSound:Play()
                wait(1)
                CanAttack = true
                AttackAnim:Stop()
                ChillAnim:Play()
            else
                print("Found a invalid target")
            end
        end)
    end
end)

Tool.Equipped:Connect(function()
    Character = Tool.Parent
    Animator = Character.Humanoid:WaitForChild("Animator")
end)

This is just a suggestion

Seems like it would work although Roblox recommends that “If the Humanoid is controlled by a particular client, as is the case with Player Characters then Animations should be loaded and played from that client.” As seen here. They recommend only loading animations through a server script if the “Humanoid belongs to a NPC (Non Player Character) which the server has network ownership of.”

Fair enough, edited it for the Animator only