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

Animation not playing on touch through function?

Asked by 6 years ago
local animation = Instance.new("Animation")
animation.AnimationId = "http://roblox.com/Asset?ID=2017727992"
local player = game.Players.LocalPlayer
local char = player.Character
if not player.Character then
     repeat wait () until player.Character
end

local animTrack = player.char.Humanoid:Load animation(animation)

function touch(hit)
          animTrack:Play()
end

game.Workspace.Base.Touched:connect(touch)

What this is supposed to do is play a swimming animation when the player touches the ocean, in which Base in the workspace is the ocean, and yes it is a part. Nothing appears in the output log as an error, but the animation doesn't play. I even tested it with another part and it didn't work. I asked my friend who can script and he said the animation needs to the load the current character. As of now, I cant test any scripts so I have to be on mobile. I would appreciate any feedback.

1 answer

Log in to vote
0
Answered by 6 years ago

Your error is on line nine. There is a space in LoadAnimation, and Animation was made lowercase. To fix this:

local animTrack = char.Humanoid:LoadAnimation(animation)

You shouldn’t be using the Touched event locally.

-- Server script inside game.Workspace.Base

local anim = Instance.new"Animation"
anim.AnimationId = ""-- put your id here
anim.Parent = script.Parent -- needs a parent, else can’t exist

script.Parent.Touched:Connect(function(part)
    if part.Parent:FindFirstChild"Humanoid" then
        part.Parent.Humanoid:LoadAnimation(anim):Play()
    end
end)
0
doesnt work. no errors appear in the output log but the animation doesnt play ScrubSadmir 200 — 6y
Ad

Answer this question