Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I am gettin' an error that I cannot fix.Can you guys help me?

So basically,I am making a matchmaking that should send you to the another server after there is x amount of people in the table.But when I try to teleport players from the table I get error.(Players get into the table after they click a button that fires remote event) Argument 3 missing or nil.I don't know what should I do to fix it.

Module script:


	local TS = game:GetService("TeleportService")
		local isReserved = game.PrivateServerId ~= "4999054674" and 		 
 										game.PrivateServerOwnerId == 131944414

	
	players_InQueue = {}
	inMatchmaking = false
	
	
	module.AddPlr = function(player)
		game.ReplicatedStorage.Remote.ready.OnServerEvent:Connect(function(player)
						print("remote is fired")
						for i = 1,#players_InQueue,1 do
							if player.Name == players_InQueue[i] then
								inMatchmaking = true
							end
						end
						
						if inMatchmaking == false then
							print("adding to table")
							table.insert(players_InQueue,#players_InQueue+1,player.Name)
						else
							print("player is already in table")
						end
						
						for i = 1,#players_InQueue,1 do
							print(players_InQueue[i])
						end
						
					inMatchmaking = false
			end)	
	end
	
	module.RemovePlr = function(player)
		local allPlrs = game.Players:GetChildren()

		for i = 1,#players_InQueue,1 do
			if player.Name == players_InQueue[i] then
				table.remove(players_InQueue,i)
				print("Player left the game")
			end
		end				
	end
			
			
			local player1 = players_InQueue[1]
	module.plrTP = function(player)	
			while true do wait()
			if #players_InQueue == 1 then
				print("there is enough players for a match")
				TS:TeleportToPrivateServer(game.PlaceId,isReserved,player1)
				print("teleporting")
			end
		end
	end

return module

Normal script :

local matchModule = require(script.Parent.modules.matchmaking)

game:GetService("Players").PlayerAdded:Connect(function(player)
	matchModule.AddPlr(player)
		matchModule.plrTP()
end)

game:GetService("Players").PlayerRemoving:Connect(function(player)
	matchModule.RemovePlr(player)
end)


2 comments

0

What line is it on?

0

On line 51 in module script.

1 answer

✓ Accepted answer

I believe the problem is that you are trying to do this all inside a module script. They don't work the same as regular scripts in that they don't run and they don't save data like normal scripts do. So right off the bat, I noticed you initiated players_InQueue to be empty, but in the first loop you have in AddPlr, you want to search from 1 to the number of players in queue which is 0.

players_InQueue = {}
inMatchmaking = false

module.AddPlr = function(player)
	game.ReplicatedStorage.Remote.ready.OnServerEvent:Connect(function(player)
		print("remote is fired")
			for i = 1,#players_InQueue,1 do
				if player.Name == players_InQueue[i] then
					inMatchmaking = true
				end
			end

What you need to do is rework your module script so that the event is being called outside the module in your regular script, and then have it send the values you need to the functions in your module script.

2 comments

0

Okay,thanks!

0

Since this answers your question, then mark it as accepted.

This discussion is preserved as it was. New answers, comments, and votes are closed.