Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to make a random 2-person teleport that WORKS, help?

Asked by 9 years ago

What I need is a way to make a script that will check the amount of players in the server, do a countdown and execute another script that teleports 2 random players that are in the game to 2 destinations (222.598, 73.536, -925.25 and 222.598, 73.536, -876.25) and after the two players are teleported, they receive swords and duel.

I have tried numerous amounts of code from many different sources, but every single one of them has failed. I do have a little bit in knowledge of Lua, but I've just now learned that knowledge.

This is one of the codes that I have tried.

players = game.Players:GetChildren()

players[math.random(1, #players)]:MoveTo(Vector3.new(222.598, 73.536, -876.25)
players[math.random(1, #players:MoveTo(Vector3.new(222.598, 73.536, -925.25)


1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 years ago

Try this:

Plr1=nil
Plr2=nil
repeat wait() until game.Players.NumPlayers>=2 --Makes sure that there is at least 2 players in the game.

Players=game.Players:GetChildren()
Plr1=Players[math.random(1, #Players)] --Sets Plr1

while Plr1==Plr2 do --Repeats until Plr1 is different than Plr2
Players=game.Players:GetChildren()
Plr2=Players[math.random(1, #Players)] --Sets Plr2
end

Plr1.Character.HumanoidRootPart.CFrame=CFrame.new(Vector3.new(222.598, 73.536, -876.25))
Plr2.Character.HumanoidRootPart.CFrame=CFrame.new(Vector3.new(222.598, 73.536, -925.25))

Anyways, this should work now. If you have any questions or problems, please leave a comment below. Hope I helped :P

0
Only one of the players were teleported mlcroblox 0 — 9y
0
Ah, sorry about that. I fixed it. It should work now. dyler3 1510 — 9y
0
I removed the 'while Plr1==Plr2 do --Repeats until Plr1 is different than Plr2' bit and it worked. mlcroblox 0 — 9y
0
Thank you for helping me out, as it is working. Now I need to peice together a round system and something to detect if the player is dead. mlcroblox 0 — 9y
View all comments (2 more)
0
No prob. Glad I could help. If you need any help with either of those, i'd be glad to assist. dyler3 1510 — 9y
1
I recommend implementing each part (The teleporting, and the get player) into seperate functions. This would be easier later on so you can call them in the rounds. ie PickPlayers() then Teleport(). AmericanStripes 610 — 9y
Ad

Answer this question