--// gets gun values from configuration folders

function module.getValue(folder : Instance, name : string)
	return folder:WaitForChild(name,1000).Value
end

function module.loadAnimation(folder : Instance, name : string, animator : Animator)
	return animator:LoadAnimation(folder:WaitForChild(name, 1000))
end

function module.getHumanoidFromPart(part : BasePart)
	local parent = part.Parent
	if parent ~= workspace and not parent:IsA("Accessory") then
		local Humanoid = parent:FindFirstChildWhichIsA("Humanoid",true)
		return Humanoid
	elseif part.Parent:IsA("Accessory") then
		parent = part.Parent.Parent
		local Humanoid = parent:FindFirstChildWhichIsA("Humanoid",true)
		return Humanoid
	end
end

function module.getRandomInstanceOfType(folder : Instance, instanceType : string)
	local folderChildren = folder:GetChildren()
	local random
	repeat random = folderChildren[math.random(1,#folderChildren)] until random:IsA(instanceType)
	return random
end

function module.normalIdFromVector(vector)
	print(vector)
	local epsilon = 0.01
	for _, normalId in pairs(Enum.NormalId:GetEnumItems()) do
		if vector.unit:Dot(Vector3.FromNormalId(normalId)) > 1 - epsilon then
			print(normalId)
			return normalId
		end
	end
end

function module.SetStatValue(player : Player, statName : string, newValue : number)
	local leaderstatsFolder = player:WaitForChild("leaderstats", 1000)
	if leaderstatsFolder then
		local stat = leaderstatsFolder:WaitForChild(statName, 1000)
		if stat then
			stat.Value = newValue
		else
			return false
		end
	else
		return false
	end
end

function module.GetStatValue(player : Player, statName : string)
	local leaderstatsFolder = player:WaitForChild("leaderstats", 1000)
	if leaderstatsFolder then
		local stat = leaderstatsFolder:WaitForChild(statName, 1000)
		if stat then
			return stat.Value
		else
			return false
		end
	else
		return false
	end
end

return module
