--- Alternative to WaitForChild which doesn't error and has custom wait time
local function WaitFor(parent, index) --- funny
	if not parent then
		return _L.Print("Failed to grab " .. index .. " (" .. parent.Name .. " is nil)", true)
	end
	local _t = tick()
	while (tick() - _t) <= waitTimeout do
		local child = parent:FindFirstChild(index)
		if child then
			return child
		end
		_L.Services.RunService.Heartbeat:Wait()
	end
	return _L.Print("Failed to grab " .. index, true)
end


Player.Get = function(instance, player)
	if isClient then
		player = player or game.Players.LocalPlayer
	end
	player = (type(player) == "string" and game.Players:FindFirstChild(player) or player)
	instance = instance or "Player"
	instance = string.lower(instance)
	
	--- Wait for player + character to EXIST!
	local _t = tick()
	while (player and (not player.Character) and (tick() - _t < waitTimeout)) do  _L.Services.RunService.Stepped:Wait()  end
	if (not player) or (tick() - _t) >= waitTimeout then  return  end
	
	--- Get humanoid & rigtype
	local humanoid = player.Character:FindFirstChild("Humanoid")
	local rigType = defaultRigType --- this will be default if humanoid cannot be read
	if humanoid then
		rigType = humanoid.RigType
	end
	
	--- R6 Compatibility
	if rigType == Enum.HumanoidRigType.R6 then
		if instance == "torso" then
			return WaitFor(player.Character, "Torso")
		elseif instance == "leftarm" then
			return WaitFor(player.Character, "LeftArm")
		elseif instance == "leftleg" then
			return WaitFor(player.Character, "LeftLeg")
		elseif instance == "rightarm" then
			return WaitFor(player.Character, "RightArm")
		elseif instance == "rightleg" then
			return WaitFor(player.Character, "RightLeg")
		end
	end
	
	--- R15 + everything else
	if instance == "player" or (not instance) then
		return player
	elseif instance == "character" then
		return player.Character
	elseif instance == "head" then
		return WaitFor(player.Character, "Head")
	elseif instance == "torso" or instance == "uppertorso" then
		return WaitFor(player.Character, "UpperTorso")
	elseif instance == "rootpart" or instance == "humanoidrootpart" then
		return WaitFor(player.Character, "HumanoidRootPart")
	elseif instance == "humanoid" then
		return WaitFor(player.Character, "Humanoid")
	elseif instance == "lowertorso" then
		return WaitFor(player.Character, "LowerTorso")
	elseif instance == "leftfoot" then
		return WaitFor(player.Character, "LeftFoot")
	elseif instance == "lefthand" then
		return WaitFor(player.Character, "LeftHand")
	elseif instance == "leftlowerarm" then
		return WaitFor(player.Character, "LeftLowerArm")
	elseif instance == "leftlowerleg" then
		return WaitFor(player.Character, "LeftLowerLeg")
	elseif instance == "leftupperarm" then
		return WaitFor(player.Character, "LeftUpperArm")
	elseif instance == "leftupperleg" then
		return WaitFor(player.Character, "LeftUpperLeg")
	elseif instance == "rightfoot" then
		return WaitFor(player.Character, "RightFoot")
	elseif instance == "righthand" then
		return WaitFor(player.Character, "RightHand")
	elseif instance == "rightlowerarm" then
		return WaitFor(player.Character, "RightLowerArm")
	elseif instance == "rightlowerleg" then
		return WaitFor(player.Character, "RightLowerLeg")
	elseif instance == "rightupperarm" then
		return WaitFor(player.Character, "RightUpperArm")
	elseif instance == "rightupperleg" then
		return WaitFor(player.Character, "RightUpperLeg")
	elseif instance == "root" then
		return WaitFor(WaitFor(player.Character, "LowerTorso"), "Root")
	elseif instance == "waist" then
		return WaitFor(WaitFor(player.Character, "UpperTorso"), "Waist")
	elseif instance == "neck" then
		return WaitFor(WaitFor(player.Character, "Head"), "Neck")
	elseif instance == "leftankle" then
		return WaitFor(WaitFor(player.Character, "LeftFoot"), "LeftAnkle")
	elseif instance == "leftwrist" then
		return WaitFor(WaitFor(player.Character, "LeftHand"), "LeftWrist")
	elseif instance == "leftelbow" then
		return WaitFor(WaitFor(player.Character, "LeftLowerArm"), "LeftElbow")
	elseif instance == "leftknee" then
		return WaitFor(WaitFor(player.Character, "LeftLowerLeg"), "LeftKnee")
	elseif instance == "leftshoulder" then
		return WaitFor(WaitFor(player.Character, "LeftUpperArm"), "LeftShoulder")
	elseif instance == "lefthip" then
		return WaitFor(WaitFor(player.Character, "LeftUpperLeg"), "LeftHip")
	elseif instance == "rightankle" then
		return WaitFor(WaitFor(player.Character, "RightFoot"), "RightAnkle")
	elseif instance == "rightwrist" then
		return WaitFor(WaitFor(player.Character, "RightHand"), "RightWrist")
	elseif instance == "rightelbow" then
		return WaitFor(WaitFor(player.Character, "RightLowerArm"), "RightElbow")
	elseif instance == "rightknee" then
		return WaitFor(WaitFor(player.Character, "RightLowerLeg"), "RightKnee")
	elseif instance == "rightshoulder" then
		return WaitFor(WaitFor(player.Character, "RightUpperArm"), "RightShoulder")
	elseif instance == "righthip" then
		return WaitFor(WaitFor(player.Character, "RightUpperLeg"), "RightHip")
	elseif instance == "playergui" then
		return player:WaitForChild("PlayerGui")
	elseif instance == "starterplayer" then
		return player:WaitForChild("StarterPlayer")
	elseif instance == "mouse" then
		return player:GetMouse()
	elseif instance == "camera" then
		return game.Workspace.CurrentCamera
	elseif instance == "name" then
		return player.Name
	end
end