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

Attempt to index nil with 'LoadAnimation' - Idk?, ahhh

Asked by 2 years ago

local Distance = 100 local Debounce = false local Player = game.Players.LocalPlayer wait(3) local Humanoid = Player:WaitForChild("Humanoid", 4) local TeleportingAnim = script:WaitForChild("TeleportingAnim", 4)

script.Parent.Activated:Connect(function() local TeleportingAnimLoad = Humanoid:LoadAnimation(TeleportingAnim) local MousePos = Player:GetMouse().Hit.Position local Plr,MousePos = Player.Character.PrimaryPart.Position,MousePos local Magnitude = (Plr - MousePos).Magnitude if Debounce == false then
if Magnitude <Distance then TeleportingAnimLoad:Play() Debounce = true wait(2) Player.Character.PrimaryPart.CFrame = CFrame.new(MousePos) wait(1.5) Debounce = false end end end)

0
humanoid is in the character, not the player. Dexiber 272 — 2y
0
humanoid is in the character, not the player. Dexiber 272 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

The player does not hold the Humanoid instance, only the player's character does.

In order for this code to work, you need to also get the player's character by using:

local character = Player.character or Player.CharacterAdded:Wait()

and then attempt to get the humanoid after by doing:

local Humanoid = character:WaitForChild("Humanoid")

Protip: Use the player's animator for animations, as Humanoid:LoadAnimation is currently deprecated in favor of using Animator:LoadAnimation.

You can get the player's animator by doing:

local animator = Humanoid:FindFirstChild("Animator")
Ad

Answer this question