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