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.
local tool = script.Parent
local inputService = game:GetService"UserInputService"
local rep = game:GetService"ReplicatedStorage"
local equipped = false
tool.Equipped:Connect(function(mouse)
equipped = true
inputService.InputBegan:Connect(function(input
if input.KeyCode == Enum.KeyCode.T and equipped then
rep.BlockAnim:FireServer(tool.BlockAnimation)
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)
anim:Play()
end)
rep.UnblockAnim.OnServerEvent:Connect(function(plr)
anim:Stop()
end)
1 comment
is it a LocalScript or just a normal Script?