How to create an action for one of the two selected players (script)

Hi, I don’t know if what I’m asking is very difficult or easily achievable. In fact it is simple to explain, I would like to make it so that for 2 players randoms selected, if one touches a parts then an action (teleportation or others) is carried out for the other player, and I would also like to know how to make sure that both players are selected at a specific time, for example when both arrive in the same place. Sorry if my explanations are not clear (I don’t speak English well), I can rephrase. Hopefully it won’t be too complicated to get help, thanks

Here is a script (not working now and not complete i don’t know how to do it)
Edit : sorry if this script hurts your eyes I’m a beginner scripter

local playertable = game:GetService("Players"):GetPlayers()
local randomPlayer1 = playertable[math.random(1, #playertable)]

table.remove(playertable, table.find(playertable, randomPlayer1))
local randomPlayer2 = playertable[math.random(1 , #playertable)]

function onTouch(hit)
	if hit.Parent == randomPlayer1 then 
		print("hii")
	end
end
game.Workspace.fincourse.Touched:Connect(onTouch)

Your current onTouch function is using the reference to the player’s character, while the chosen random player is using the player object, and not the player’s character, which is why it is most likely not printing anything.

You will need to use: GetPlayerFromCharacter() which is a function of the Players service.

local function onTouch(hit)
    local playerThatTouched = game.Players:GetPlayerFromCharacter(hit.Parent)
    if playerThatTouched then
        print(playerThatTouched.Name)
        -- then you can compare playerThatTouched with randomPlayer1 and 2
    end
end

Hello, thank you for your answer. Unfortunately the output does not react when I touch the part

local playertable = game:GetService("Players"):GetPlayers()
local randomPlayer1 = playertable[math.random(1, #playertable)]

table.remove(playertable, table.find(playertable, randomPlayer1))
local randomPlayer2 = playertable[math.random(1,#playertable)]

local function onTouch(hit)
	local playerThatTouched = game.Players:GetPlayerFromCharacter(hit.Parent)
	if playerThatTouched then
		print(playerThatTouched.Name)
		-- then you can compare playerThatTouched with randomPlayer1 and 2
	end
end
game.Workspace.fincourse.Touched:Connect(onTouch)

Without wanting to be heavy or ask for too much help, can someone just tell me if with Dev_Ryan’s script(above) I’m close to success or if I’m on the wrong road? thanks