I have a script and animation for punching, but I don't know how to make the player use the animation. I've been trying to figure it out so can someone help me.
Here's the code. It's a script in "ServerScriptService" The main part I'm trying to fix is lines 25 and 26
local uis = game:GetService("UserInputService")
game.Players.PlayerAdded:Connect(function(player)
local animHold = Instance.new("StringValue")
local plrgui = player:WaitForChild("PlayerGui")
local setngs = plrgui:WaitForChild('Settings')
local KeyReq = setngs:WaitForChild('Key')
local frame = setngs:WaitForChild("Frame")
local button = frame:WaitForChild("PunchBtn")
local plr = player.Name
local plrmodel = workspace:WaitForChild(plr)
local char = plrmodel:WaitForChild("Character")
local humanoid = char:WaitForChild("Humanoid")
animHold.Name = 'Punch'
local plr = workspace:WaitForChild(player.Name)
local animate = plr:WaitForChild("Animate")
animHold.Parent = animate
local anim = Instance.new("Animation", animHold)
anim.AnimationId = 'http://www.roblox.com/asset/?id=2889390323'
if uis.KeyboardEnabled then
uis.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode[KeyReq] then
print('Punch')
local animTrack = humanoid:LoadAnimation(anim)
animTrack:Play()
end
end)
uis.InputEnded:Connect(function(input, gameProcessedEvent)
end)
elseif uis.GamepadEnabled then
uis.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.ButtonR2 then
local animTrack = humanoid:LoadAnimation(anim)
animTrack:Play()
print("Punch")
uis.InputEnded:Connect(function(input, gameProcessedEvent)
end)
end
end
end)
end
end)

1 comment
https://developer.roblox.com/articles/using-animations-in-games