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

How can you do like when right leg touched animation plays?

It's like an how can u make a player play an animation when he gets touched by the leg? like Roblox soccer when you tackle a player they play an animation of a tackled person?

2 answers

✓ Accepted answer

Humanoids have an event called .Touched. You could listen for when a character's limb gets touched via like so

local players = game:GetService("Players")
local humanoidConnections = {}

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local humanoid = char.Humanoid or char:WaitForChild("Humanoid")
		if humanoidConnections[player] then humanoidConnections[player]:Disconnect() end
		humanoidConnections[player] = humanoid.Touched:Connect(function(touchingPart,itTouched) -- Here is where it detects when a part touches the characters humanoid.
			-- play the animation or do animations client side for all clients. Up to you depending on what game and how much work the server is already doing
		end)
	end
end

players.PlayerRemoving:Connect(function(player) -- Remove player from table to prevent memory leaks.
	if humanoidConnections[player] then humanoidConnections[player] = nil end
-- No need to disconnect because character is destroyed when a player leaves and destroy disconnects connections.
end)

You can read more about it here:

Humanoid.Touched

If this helped I would appreciate an upvote or solve. Good luck!

Best Regards, -Syn

1 comment

0

Ah, I miss read you're question. Ok, read up on this article this will show you how to properly load and play animations: https://developer.roblox.com/en-us/api-reference/function/Humanoid/LoadAnimation

As he said, but make sure the animations have the "action" level, or the tackled anim will be overlayed by the walking one and cause issues, Thanks!

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