If anyone could help me fix this script, I would appreciate it a lot:
1 | xw = script.Parent.PushDoorAnimation |
2 |
3 | function PushDoor() |
4 | wait( 0.1 ) |
5 | game.Players.LocalPlayer:Play(xw) |
6 | end |
7 | script.Parent.Touched:connect( function PushDoor() |
8 | end ) |
Also, how can you make it so only a humanoid can make the function play?
To make it so that only a humanoid can make the function play you need to insert a check before the function fires off the animation
i.e.
1 | script.Parent.Touched:connect( function (hit) |
2 | if hit.Parent and hit.Parent:FindFirstChild( "Humanoid" ) |
3 | then game.Players.LocalPlayer:Play(xw) |
4 | else nil |
5 | end |
Here's a code to play animation when a player touches the electric fence, you can use it if you change the variables to match your game
01 | -- Import animation |
02 | local animation = Instance.new( "Animation" ) |
03 | animation.AnimationId = "http://www.roblox.com/Asset?ID=144911345" |
04 |
05 | -- Local variables |
06 | local animTrack = nil |
07 | local canPlay = true |
08 |
09 | function playShockAnim(Source) |
10 | if canPlay then |
11 | local player = game.Players.LocalPlayer.Character |
12 | canPlay = false |
13 | animTrack = player.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid |
14 | animTrack.KeyframeReached:connect( function (keyframeName) -- Bind function to KeyframeReached event |
15 | if keyframeName = = "ElectrocuteEnd" then |