I am trying to do a punch animation everytime a player clicks a button. Using contextactionservice. Ive been hearing that mouse is way uneffiecient then contextactionservice. Here is the script:
–ContextActionService
local ContextActionService = game:GetService(“ContextActionService”)
local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local humanoid = character:WaitForChild(“Humanoid”)
local PUNCH_ACTION = Instance.new(“Animation”)
local REPEL_ACTION = Instance.new(“Animation”)
PUNCH_ACTION.AnimationId = “BasicMeeleAnimation - Roblox”
REPEL_ACTION.AnimationId = “Repel 3 - Roblox”
local function handleAction(actionName,inputState,inputObject)
if actionName ==PUNCH_ACTION and inputState == Enum.UserInputState.Begin then
local animationTrack = humanoid:LoadAnimation(PUNCH_ACTION)
animationTrack:Play()
else
print(“No”)
end
end
tool.Equipped:connect(function()
ContextActionService:BindAction(PUNCH_ACTION, handleAction, true, Enum.UserInputType.MouseButton1)
end)