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

error LoadAnimation is not a valid member of Part ?

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

3 comments

0

you need to index the parent of the newly created animation on line 2.

0

what do you mean by index?

0

The Touched event passes the base part that touched not the player and humanoid.

1 answer

✓ Accepted answer
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)

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