I keep getting "Attempt to get length of a Instance value". Please help

Hello developers!
So i have been stuck on this problem for a while now, i did the best i can and i keep recieving “attempt to get length of a instance”.

The point of the scripts is to reward the player for playing with their friends after finishing the round.

If anyone could help, i would be so thankful. I have been stuck on this issue for a long time.

Script 1 (Local script that finds the players friends)

local player = game.Players.LocalPlayer
local playerid = player.UserId
local debounce = false

while wait() do
	local friendsinserver = {}

	for i, plr in pairs(game.Players:GetChildren()) do
		if plr:IsFriendsWith(playerid) then
			if not table.find(friendsinserver, plr) then
				table.insert(friendsinserver, plr)
			end	
		end
	end
	
if game.ReplicatedStorage.RoundResultEnabed.Value == true then
		if debounce == false then
			debounce = true
	if #friendsinserver <= 0 then
				script.Parent.Text = "0"
	end
	if #friendsinserver == 1 then
				script.Parent.Text = "15"
	end
	if #friendsinserver == 2 then
				script.Parent.Text = "30"
	end
	if #friendsinserver == 3 then
				script.Parent.Text = "45"
	end
	if #friendsinserver == 4 then
				script.Parent.Text = "60"
	end
	if #friendsinserver >= 5 then
				script.Parent.Text = "150"
			end
			
			game.ReplicatedStorage.PlayerTokensFromFriends:FireServer(player,friendsinserver)
		elseif game.ReplicatedStorage.RoundResultEnabed.Value == false then
			debounce = false
		end
	end	
end	

Script 2 (Script that rewards the correct amount to the player)

game.ReplicatedStorage.PlayerTokensFromFriends.OnServerEvent:Connect(function(player,friendsinserver)
	
	if #friendsinserver == 0 then
		player.Tokens.Value = player.Tokens.Value + 0
	end
	if #friendsinserver == 1 then
		player.Tokens.Value = player.Tokens.Value + 15
	end
	if #friendsinserver == 2 then
		player.Tokens.Value = player.Tokens.Value + 30
	end
	if #friendsinserver == 3 then
		player.Tokens.Value = player.Tokens.Value + 45
	end
	if #friendsinserver == 4 then
		player.Tokens.Value = player.Tokens.Value + 60
	end
	if #friendsinserver == 5 then
		player.Tokens.Value = player.Tokens.Value + 150
	end
	if #friendsinserver == 6 then
		player.Tokens.Value = player.Tokens.Value + 150
	end
	if #friendsinserver == 7 then
		player.Tokens.Value = player.Tokens.Value + 150
	end
	if #friendsinserver == 8 then
		player.Tokens.Value = player.Tokens.Value + 150
	end
	if #friendsinserver == 9 then
		player.Tokens.Value = player.Tokens.Value + 150
	end
end)

where does the error occur?

It occurs in script 2 when it tries to detect if #friendsinserver == 0.

game.ReplicatedStorage.PlayerTokensFromFriends.OnServerEvent:Connect(function(player,friendsinserver)
	
	if #friendsinserver:GetChildren() == 0 then
		player.Tokens.Value = player.Tokens.Value + 0
	end
	if #friendsinserver:GetChildren() == 1 then
		player.Tokens.Value = player.Tokens.Value + 15
	end
	if #friendsinserver:GetChildren() == 2 then
		player.Tokens.Value = player.Tokens.Value + 30
	end
	if #friendsinserver:GetChildren() == 3 then
		player.Tokens.Value = player.Tokens.Value + 45
	end
	if #friendsinserver:GetChildren() == 4 then
		player.Tokens.Value = player.Tokens.Value + 60
	end
	if #friendsinserver == 5 then
		player.Tokens.Value = player.Tokens.Value + 150
	end
	if #friendsinserver:GetChildren() == 6 then
		player.Tokens.Value = player.Tokens.Value + 150
	end
	if #friendsinserver:GetChildren() == 7 then
		player.Tokens.Value = player.Tokens.Value + 150
	end
	if #friendsinserver:GetChildren() == 8 then
		player.Tokens.Value = player.Tokens.Value + 150
	end
	if #friendsinserver:GetChildren() == 9 then
		player.Tokens.Value = player.Tokens.Value + 150
	end
end)
2 Likes

Thank you so much for the support!