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

[Sword Animation/Damage Script] What can i do to make this script work?

So i change the localscript .connect on lines 3 and 9 to :Connect, and the damage works fine but still the animation isn't working :( IDK what ive done wrong.

ScreenShots of my games setup is shown in the screenshots, code will be pasted below:

Link to Game Setup: https://imgur.com/a/ejoF9

Link to Script: https://imgur.com/a/Aqcmq

Link to LocalScript: https://imgur.com/a/wUxNS

Script Code:

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)

LocalScript Code:

local CanAttack = true

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

script.Parent.Activated:Connect(function()
	local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
	local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
	
	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)

3 comments

0

You're using '.connect' on line 9 on the local script code, instead of :Connect. (Tip: Use :Connect as :connect is deprecated.)

0

Also on line 3.

0

thx bro

2 answers

(there will probably be some typos)

If some of this doesn't work then pm on Roblox (I haven't tested it so)

First of all as mosski123 commented you have used :connect , which is depreceated. Use :Connect instead.

Secondly, you don't need an idle animation when using a tool.

First bit of code: You should put this code in the actual bit of the sword that does damage.

local canattack = true --you had this as a Instance before, you can just do it as variable
script.Parent.Touched:Connect(function(p) --event
	local humanoid = p.Parent:FindFirstChild("Humanoid")--checks if there is a humanoid in p
	if canattack == true and humanoid then --if canattack is false and there is a humanoid
	
		canattack = false--sets canattack to false
		
		humanoid:TakeDamage(20) 
	
	end

end)

Second bit of code:

local player = game:GetService("Players").LocalPlayer --gets player
local char = player.Character or player.CharacterAdded:Wait()--gets character
local canplay = true --can play is true

script.Parent.Activated:Connect(function() --when the player click
    local attack = char:WaitForChild("Humanoid"):LoadAnimation(script.Attack) --loads the animation into the humanoid

    if canplay == true then
        attack:Play()
       	canplay = false
        wait(1)
        attack:Stop()
        canplay = true

    end
end)

6 comments

0

first piece of code the line 4 canattack has error?

0

wat is the error? o ik why i will edit the code

0

try it now

0

tried it now and this happens: 15:34:00.052 - Players.deathblade80.Backpack.Iron Sword.LocalScript:5: bad argument #1 to 'Connect' (RBXScriptSignal expected, got function)

0

I'll add you on roblox

0

Where do I put the second code?

local canattack = true --you had this as a Instance before, you can just do it as variable
script.Parent.Touched:Connect(function(p) --event
	local humanoid = p.Parent:FindFirstChild("Humanoid")--checks if there is a humanoid in p
	if canattack == true and humanoid then --if canattack is false and there is a humanoid
		canattack = false--sets canattack to false
		humanoid:TakeDamage(1000)
	end
	if canattack == false then
		wait(5)
		canattack = true
	end
end)

Most of the code is unoriginal, I was just adding a cooldown

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