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

How to make the local player play an animation when touches a brick?

Asked by
Dwayder 29
8 years ago

If anyone could help me fix this script, I would appreciate it a lot:

1xw = script.Parent.PushDoorAnimation
2 
3function PushDoor()
4    wait(0.1)
5    game.Players.LocalPlayer:Play(xw)
6end
7script.Parent.Touched:connect(function PushDoor()
8end)

Also, how can you make it so only a humanoid can make the function play?

1 answer

Log in to vote
0
Answered by
Nogalo 148
8 years ago
Edited 8 years ago

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.

1script.Parent.Touched:connect(function (hit)
2    if hit.Parent and hit.Parent:FindFirstChild("Humanoid"
3then game.Players.LocalPlayer:Play(xw)
4else nil
5end

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
02local animation = Instance.new("Animation")
03animation.AnimationId = "http://www.roblox.com/Asset?ID=144911345"
04 
05-- Local variables
06local animTrack = nil
07local canPlay = true
08 
09function 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
View all 21 lines...
0
Thank you, I'll look forward to edit this for my game. Dwayder 29 — 8y
Ad

Answer this question