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

The animationId isn't really working and I don't know why. Anyone can help?-

The animation isn't playing. I dont really know what to write in the AnimationId. Anyone know what to do?

local player = game.Players.LocalPlayer
local db = true
local damaged = false

local anim = Instance.new("Animation")
anim.AnimationId = "5218306353"

game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not db and not damaged and hit.Parent.Humanoid ~= game.Players.LocalPlayer.Character.Humanoid then
		if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
			damaged = true
			game.ReplicatedStorage.Punch:FireServer(hit.Parent.Humanoid)
		end
	end
end)

game:GetService("UserInputService").InputBegan:Connect(function(input, event)
	if input.KeyCode == Enum.KeyCode.Q and db then
		db = false
		local playAnim = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(anim)
		playAnim:Play()
		wait(0.8)
		damaged = false
		db = true
	end
end)

2 comments

0

try? anim.AnimationId = "rbxassetid://5218306353"

0

If I understand correctly what you want, just copy the code i posted in my answer below and put it in a local script inside of StarterCharachterScripts (found in StarterPlayer)

1 answer

✓ Accepted answer

It won't work as you coded the animation on an R6 model, but you probably have game settings for R15. What you will need to do is go to Game Settings in Roblox Studio, select Avatar, then select the part that says R6 next to Avatar Type. Then Click Save

Also I recommend updating the script to this:

I also added compatibility for Xbox Users:

--add this into a local script inside of StarterPlayer.StarterCharachterScripts--

local UserInputService = game:GetService("UserInputService")
local Humanoid = script.Parent:WaitForChild('Humanoid')
local DB = false


local punchanimation = Instance.new("Animation", script)
punchanimation.AnimationId = "http://www.roblox.com/asset/?id=5218306353"
local punch = humanoid:LoadAnimation(punchanimation)
 
-- Punch keys
local q = Enum.KeyCode.Q
 
-- Return whether punch buttons are down
local function IsPunchKeyDown()
	return UserInputService:IsKeyDown(q) or UserInputService:IsGamepadButtonDown(Enum.UserInputType.Gamepad1,Enum.KeyCode.ButtonL1)
end
 
-- Handle user input began differently depending on whether a key is pressed
local function Input(input, gameProcessedEvent)
	if IsPunchKeyDown() and DB == false then
		DB = true
		punch:play()
		Humanoid.Parent.RightHand.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= game.Players.LocalPlayer.Character..Name then
				if game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
					hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 20
				end
			end
		end)
		wait(0.8)
		DB = false
	end
end
 
--Activate Punch
UserInputService.InputBegan:Connect(Input)
UserInputService.InputChanged:Connect(Input)
UserInputService.InputEnded:Connect(Input)

1 comment

0

I realized it yesterday. I made it work.

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