If anyone could help me fix this script, I would appreciate it a lot:
xw = script.Parent.PushDoorAnimation function PushDoor() wait(0.1) game.Players.LocalPlayer:Play(xw) end script.Parent.Touched:connect(function PushDoor() 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.
script.Parent.Touched:connect(function (hit) if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then game.Players.LocalPlayer:Play(xw) else nil 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
-- Import animation local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/Asset?ID=144911345" -- Local variables local animTrack = nil local canPlay = true function playShockAnim(Source) if canPlay then local player = game.Players.LocalPlayer.Character canPlay = false animTrack = player.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid animTrack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event if keyframeName == "ElectrocuteEnd" then canPlay = true end end) animTrack:Play() -- Start the animation end end