Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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

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 johndeer2233 439 — 4y
Ad
Log in to vote
0
Answered by
IrishFix 124
4 years ago

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!

Answer this question