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)
(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)
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