If checks absolubtly broke

Hello, I need some help, so basically, something’s not working properly.

So I am making matchmatching and this doesn’t works;

local function InsertPlayerInMatch(userId,t,index)
	assert(userId ~= nil,"user ID is nil")
	local suc,returned = pcall(Matchmatching.GetAsync,Matchmatching,"Matchs")	
	if (suc) then
		if (returned) then
			print('works.')
			local Table = returned[index]
			if (table.find(Table.Players,userId)) then
				print("found him go back :O")
				return
			end
			print('Okay...')
			table.insert(Table.Players,userId)
			local x = {Owner = --[[game.Players:GetNameFromUserIdAsync]](Table.Owner),Name = --[[game.Players:GetNameFromUserIdAsync]](userId)}
			print(x.Owner,x.Name,"at Insert function.") -- doesn't prints... WHAT?
			MessagingService:PublishAsync("PlayerJoined",x)
			Matchmatching:UpdateAsync("Matchs",function(x)
				return returned or x
			end)
			print('something stops it here D: so this doesnt prints :(')
		end
	end
end

‘returned’ is a list returning all matchs, like this;
{{Players = {a list of the IDs of player inside} ,Owner = ownerUserId(creator of match) }}.

But, for some reason it doesn’t works, this is how I call it;
Player enters match;

RepStorage.Events.EnterMatchmatching.OnServerEvent:Connect(function(Player)
	if (PlayersInside[Player]) then
		return
	end
	PlayersInside[Player] = true
	print('Fired.')
	MessagingService:PublishAsync('MatchmatchingEnter',Player.UserId)
end)

Now, this is what I do to check.

MessagingService:SubscribeAsync("MatchmatchingEnter",function(msg)
	local UserId = msg.Data
	print(UserId,"Now trying to enter a match.")
	local suc,returned = pcall(Matchmatching.GetAsync,Matchmatching,"Matchs")
	warn(suc)
	if (suc) then
		print("This is  printing.")
		warn(returned)
		if (returned) then
			print("But this is NOT printing.")
			table.sort(returned,
				function(a,b)
					return (a.Players < b.Players)
				end
			)
			local x = false
			for i,v in pairs(returned) do
				print(#v.Players < Settings.MaxPlayers)
				if (#v.Players < Settings.MaxPlayers) then
					InsertPlayerInMatch(UserId,returned,i)
					print('PLAYER NAMED',game.Players:GetNameFromUserIdAsync(UserId),"JOINING",game.Players:GetNameFromUserIdAsync(v.Owner),"MATCH.")
					x = true
					print('inserting')
					break
				end
			end
			if (not x) then
				createMatch(UserId)
			end
		else
			print('creating a new match. CREATED BY:',game.Players:GetNameFromUserIdAsync(UserId))
			createMatch(UserId)
		end
	end
end)

Basically, checking if there’s matchs the player can join, otherwise, add him to other match.

But…
image
IT’s not PRINTING!
NO clue why.
returned returns a table, I printed it, but let’s just suppose returned it’s nil, the else is not firing, not working.

This doesn’t prints at all.
hmm… I tested printing( returned ) and yep, it was nil.
image

So then why the else is not working?


But.

else
			print('k.')
			print('creating a new match. CREATED BY:',game.Players:GetNameFromUserIdAsync(UserId))
			createMatch(UserId)

THIS DOESNT WORKS.
Output;
image
Cool, returned is nil, now run ‘k’
the thing is, I think game.Players:GetNameFromUserIdAsync()
is yielding insanely.

This was tested on “test”

But, when I test it on Run, it works.

Any idea why game.Players:GetNameFromUserIdAsync() doesn’t works on Player1 and Player2? :thinking:

Player1 and Player2 have a negative Id (-1 and -2 respectively)
I’m not sure if GetNameFromUserIdAsync supports negative numbers.

I found a workaround to this in an old post

2 Likes