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

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

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.

1 comment

0

is it a LocalScript or just a normal Script?

1 answer

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)

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