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

error LoadAnimation is not a valid member of Part ?

Asked by 6 years ago
Edited 6 years ago

I made a script for swimming and its saying "LoadAnimation is not a valid member of Part" when ever I touch the Part named Water this is the script:

function Swimming(player,Humanoid)
    local animation=Instance.new("Animation")
    animation.AnimationId="http://www.roblox.com/Asset?ID=1010301459"
    local animTrack=player:LoadAnimation(animation)
    animTrack:Play()   
 print "going to swim this player on:"
  local debounce=false
    if debounce==false then
       debounce = true
      print(player.Model.Name)
      script.Parent=workspace.Water
 end
end
script.Parent.Touched:Connect(Swimming)

this is the first animation script I made, what I want it to do is play my animation when ever I touch the scripts parent but the error I get in the output is "LoadAnimation is not a valid member of Part" please help me fix this.thx

0
you need to index the parent of the newly created animation on line 2. PyccknnXakep 1225 — 6y
0
what do you mean by index? redjacob02 20 — 6y
0
The Touched event passes the base part that touched not the player and humanoid. User#5423 17 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago
local debounce = false -- debounce needs to be outside or else it will be set to false every time the function runs
function Swimming(part)
    local player = game.Players:GetPlayerFromCharacter(part.Parent) -- checks if limb touched by getting the player from its character
    if player then
        if debounce == false then   
            local animation = Instance.new("Animation") -- loads animation
            animation.AnimationId = "http://www.roblox.com/Asset?ID=1010301459"
            animation.Parent = player.Character.Humanoid -- sets animation parent to humanoid
            local animTrack = player.Character.Humanoid:LoadAnimation(animation) --loads anim  
            debounce = true --sets db to true
            animTrack:Play() -- plays
            print("swimming player: " .. player.Character.Name) -- prints "swimming player: creeperhunter76"
            wait(4)
        end
        debounce = false
    end
end
script.Parent.Touched:Connect(Swimming)

Ad

Answer this question