So I am trying to make it so that when the player is touched by the handcuff it will play an animation. The script is a server script inside of StarterCharacterScripts.
Here is my code:
game.Players.PlayerAdded:Connect(function(player)
player.Backpack.Handcuff.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local animation = hit.Parent.Character.Animator:LoadAnimation(script.Animation)
animation:Play()
end
end)
end)
local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
return animationTrack
end
Remove PlayerAdded function - it’s not needed, and only replicates the function (allowing it to occur more than once depending upon how many players joined).
local part = --direct pathway for your part that listens to .Touched
part.Touched:Connect(function(h)
local hum = h.Parent:FindFirstChild("Humanoid")
--checking for "Humanoid" and "Animator"
if not hum then return
elseif not hum:FindFirstChildOfClass("Animator") then local inst = Instance.new("Animator"); inst.Parent = hum end
--playing the animation
local animator = hum:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(script.Animation)
animationTrack:Play()
end)