Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Animation not playing on touch through function?

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

###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)

1 comment

0

doesnt work. no errors appear in the output log but the animation doesnt play

This discussion is preserved as it was. New answers, comments, and votes are closed.