I am trying to constantly check if 2 players are on a spot at the same time, they get on the spot by using a ProximityPrompt. And when the players are both on the spot, it should teleport them to a designated location, written as “rInGameTP”/bInGameTP"
this is my code.
rPrompt.Triggered(function(rPlr)
if bTaken.Changed or rTaken.Changed then
if bTaken.Value == true and rTaken.Value == true then
print('Game 1 Ready')
wait(1)
bPlr.Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(BInGameTP.Position)
rPlr.Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(RInGameTP.Position)
end
end
end)
end)
You could insert the player into a table [if he is not there],
And when another player triggers the prompt, check if any player inside that table is at the same spot as this current player.
local otherPlayer = nil
proximityPrompt.Triggered:Connect(function(player)
if otherPlayer == nil then
-- set over player to the player that triggered the prompt
otherPlayer = player
-- wait 1 second
task.wait(1)
-- if the other player is no longer this player then exit
if otherPlayer ~= player then return end
-- set other player to nil
otherPlayer = nil
else
-- teleport the 2 players
player.Character.PrimaryPart.CFrame = BInGameTP.CFrame
otherPlayer.Character.PrimaryPart.CFrame = BInGameTP.CFrame
-- set otherplayer to nil
otherPlayer = nil
end
end)