Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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)
0
You're using '.connect' on line 9 on the local script code, instead of :Connect. (Tip: Use :Connect as :connect is deprecated.) awfulszn 394 — 6y
0
Also on line 3. awfulszn 394 — 6y
0
thx bro deathblade80 0 — 6y

2 answers

Log in to vote
0
Answered by
iddash 45
6 years ago
Edited 6 years ago

(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)
0
first piece of code the line 4 canattack has error? deathblade80 0 — 6y
0
wat is the error? o ik why i will edit the code iddash 45 — 6y
0
try it now iddash 45 — 6y
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) deathblade80 0 — 6y
View all comments (2 more)
0
I'll add you on roblox deathblade80 0 — 6y
0
Where do I put the second code? SORENSTONE 0 — 5y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
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

Answer this question