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

Why won't my sword code run animations?

Asked by 9 years ago

I have been working on this script for a sword, based on the Roblox U tutorials, and I have no idea why it is not working. I have gone through and fixed all of the errors that I could find, so the sword should be running animations when it is clicked. Please help!

Here is the SwordScript:

--Made by Legobrain9275

local tool = script.Parent

local handle = tool:WaitForChild("Handle")

local event = tool:WaitForChild("RemoteEvent")

local speedboost = 1.25

local damage = 26

local swingtime = 1

local lastclick = tick()

local combowindow = .5

local combo = 0

local SlashSound = game.StarterPack.Sword.Handle.SlashSound

local LungeSound = game.StarterPack.Sword.Handle.LungeSound

local OverheadSound = game.StarterPack.Sword.Handle.OverheadSound

handle.Touched:connect(function(hit)

    if equipped and character and humanoid and humanoid.Health > 0 and hit and not hit:IsDescendantOf(character) then
        local targethumanoid = hit.Parent:FindFirstChild("Humanoid")
        if targethumanoid and targethumanoid.Health > 0 and not hithumanoids(targethumanoid) then
            hithumanoids = true
            targethumanoid:TakeDamage(damage * combo)
        end
    end
end)

tool.Activate:connect(function()
    local clickdelta = tick() - lastclick
    if clickdelta > swingtime then
        lastclick = tick()
        hithumanoids = false
        if clickdelta < swingtime + combowindow then
            combo = (combo + 1) % 3
        else 
            combo = 0
        end
        if player then
            if combo == 0 then
                event:FireClient(player, "RunAnimation", "SlashAnim2")
                SlashSound:Play()
            elseif combo == 1 then
                event:FireClient(player, "RunAnimation", "ThrustAnim2")
                OverheadSound:Play()
            elseif combo == 2 then
                event:FireClient(player, "RunAnimation", "OverheadAnim2")
                LungeSound:Play()
            end
        end
    end
end)

tool.Equipped:connect(function()
    equipped = true
    combo = 0
    lastclick = tick()
    character = tool.Parent
    local player = game.Players:GetPlayerFromCharacter(character)
    humanoid = character:FindFirstChild("Humanoid")
    if humanoid ~= nil then
        humanoid.WalkSpeed = humanoid.WalkSpeed * speedboost
    else
        character = nil
    end

end)

tool.Unequipped:connect(function()
    equipped = false
    if humanoid then
        humanoid.WalkSpeed = humanoid.WalkSpeed / speedboost
    end
    character = nil
    humanoid = nil

end)

Here is the SwordLocalScript:

--made by Legobrain9275

local tool = script.Parent
local event = tool:WaitForChild("RemoteEvent")



event.OnClientEvent:connect(function(...)
    local tuple = {...}
    if tuple[1] == "RunAnimation" then
        local anim = tool:FindFirstChild(tuple[2])
        if anim and humanoid then
            local loadedanim = humanoid:LoadAnimation(anim)
            if loadedanim then
                loadedanim:Play()
                if themouse then
                    themouse.Icon = "rbxasset//textures\\GunWaitCursor.png"
                    wait(1)
                    themouse.Icon = "rbxasset//textures\\GunCursor.png"
                end
            end
        end
    end
end)


tool.Equipped:connect(function(mouse)
    humanoid = tool.Parent:FindFirstChild("Humanoid")
    themouse = mouse
    if humanoid then
        local anim = tool:FindFirstChild("IdleAnim3")
        if anim and humanoid then
            if loadedidleanim then
                loadedidleanim:Stop()
            end
            loadedidleanim = humanoid:LoadAnimation(anim)
            if loadedidleanim then
                loadedidleanim:Play()
            end
        local anim = tool:FindFirstChild("EquipAnim5")
        if anim and humanoid then
            local loadedanim = humanoid:LoadAnimation(anim)
            if loadedanim then
                loadedanim:Play()
            end
        end
        end
    end
    if themouse then
        themouse.Icon = "rbxasset//textures\\GunCursor.png"
    end
end)

tool.Unequipped:connect(function()
    if loadedidleanim then
        loadedidleanim:Stop()
    end
end)

`

Thank you very much to anyone who can help!

0
Code block pls. woodengop 1134 — 9y

Answer this question