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

For some reason, the block animation isnt playing, but the swing animations are?

Asked by 6 years ago

local Tool = script.Parent local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:connect(function(input)

local Character = Tool.Parent
local Humanoid = Character:FindFirstChild("Humanoid")

if input.KeyCode == Enum.KeyCode.T then
    wait(0.5)
    local BlockAnimation = Humanoid:LoadAnimation(Tool.Animation4)
    BlockAnimation:Play()
end

end)

The animations are all within the Tool itself, and this Script is inside the tool as well.

0
is it a LocalScript or just a normal Script? Professor_Boxtrot 136 — 6y

1 answer

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

RBXScriptSignal:connect() is deprecated, switch to RBXScriptSignal:Connect().

Make sure it's a LocalScript, as the UserInputService does not exist on the server. This service, as its name implies, handles user input. ANY kind of user input is to be handled on the client. Surely you want the animation to be visible to the server, and if you play it from only a LocalScript, only you could see it. I will add a remote event so the server can play the animation.

-- LocalScript
local tool = script.Parent
local inputService = game:GetService"UserInputService"
local rep = game:GetService"ReplicatedStorage"
local equipped = false -- You don't want the animation to play with the tool unequipped!

tool.Equipped:Connect(function(mouse)
    equipped = true 

    -- You can add other code for the Equipped event.

    inputService.InputBegan:Connect(function(input
        if input.KeyCode == Enum.KeyCode.T and equipped then
            -- if equipped and the key == T
            rep.BlockAnim:FireServer(tool.BlockAnimation) -- i called it BlockAnim
        end
    end)
end)

tool.Unequipped:Connect(function()
    equipped = false
    rep.UnblockAnim:FireServer()
end)

ServerScript that handles the server event:

local rep = game:GetService"ReplicatedStorage"

rep.BlockAnim.OnServerEvent:Connect(function(plr, animation)
    anim= game.Workspace[plr.Name].Humanoid:LoadAnimation(animation) -- Play the animation on the server and handle it all on here
    anim:Play()
end)

rep.UnblockAnim.OnServerEvent:Connect(function(plr)
    anim:Stop()
end)
Ad

Answer this question