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

im trying to make a punch but my script dosent load my animation how can i fix it?

this script isnt working

local player = game.Players.LocalPlayer
local user = game:GetService("UserInputService")
local mouse = player:GetMouse()
local Animation = Instance.new("Animation")
local Humanoid = player:FindFirstChild("Humanoid")
Animation.AnimationId = "http://www.roblox.com/asset/?id=2625660591"
local animationController = Instance.new("AnimationController")
local animationTrack = animationController:LoadAnimation(Animation)
animationTrack:Play()
local function onKeyDown ( key )`~~~~~~~~~~~~~~~~~

` print ("punch")

mouse.KeyDown:Connect(onKeyDown) end


1 comment

0

Try finding character too in line 5. Also are there any errors other than "my animation wont load"?

1 answer

mouse.KeyDown is deprecated use UserInputService

--< Services
local PlayerService = game:GetService('Players')
local UserInputService = game:GetService('UserInputService')

--< Variables
local Player = PlayerService.LocalPlayer
repeat wait() until Player.Character -- wait the character spawn
local Character = Player.Character

local KeyCode = Enum.KeyCode.Q -- The key of the player press to execute animation

-- Create instance
local Animation = Instance.new("Animation", Character)
Animation.AnimationId = "rbxassetid://2625660591"

--< Events
UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == KeyCode then
		local AnimationTrack = Character.Humanoid:LoadAnimation(Animation)
		AnimationTrack:Play()
	end
end)

2 comments

0

I tried it and it didnt work

1

Yes of course, my error. It work now I have testing.

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