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

How do i make an animation on a part play when a player touches it?

Asked by 1 year ago

So i have been trying to make a door animation play when touched, i tried searching it up because i had no idea how to do it and all i could see were scripts on how to make the animation play for a humanoid instead of an object, but since i have to add code or my question will get deleted, i will add this:

local PlayerAnimationFeedback = {}
local FeedbackAnimationTrack
local ANIMATION_FADE = 0.3
local ANIMATION_ID = "rbxassetid://"
function PlayerAnimationFeedback:LoadAnimation(humanoid)
    local FeedbackAnimation = Instance.new("Animation")
    FeedbackAnimation.AnimationId = ANIMATION_ID
    FeedbackAnimationTrack = humanoid:LoadAnimation(FeedbackAnimation)
    FeedbackAnimationTrack.Priority = Enum.AnimationPriority.Action
    FeedbackAnimation.Looped = true
end
function PlayerAnimationFeedback:PlayAnimation()
    FeedbackAnimationTrack:Play(ANIMATION_FADE)
    wait(FeedbackAnimationTrack.Length)
end
return PlayerAnimationFeedback


0
You could technically use a hinge constraint for it but it would be very inefficient Klui36 45 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

You have wrote that the ANIMATION__ID value is just the starting URL of an asset which is "rbxassetid://" but it must be followed with the ID of the number

You should try something liike this:

03 local PlrHits = {}
04 local ID= --whatever you want
05  function CreateTrack(IDanim,track)
06  track = nil
07  local animation = Instance.new("Animation",script)
08  animation.AnimationId = "rbxassetid://",ID
09  animation.Priority = Enum.AnimationPriority.Action
10  animation.Looped = true
11  track = humanoid:LoadAnimation(animation)
12  return track
13  end
14  
15  local tracktoplay = CreateTrack(ID)
16  door.Touched:Connect(function(hit)
17      if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= character and PlrHits[hit.Parent] == nil then
18  PlrHits[hit.Parent] = true
19  tracktoplay:Play()
20  wait(tracktoplay.Lenght)
21  PlrHits[hit.Parent] = nil
22  end
23 end)

I made it in way a way i never did before so i am not sure if it is going to work. I usually make it in 3 lines but since you started with a function, i decided to make it this way. If you want me to tell you the way i do it usually ask me c:

Ad

Answer this question