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

I Need to Teleport Players?

Asked by 10 years ago

My game has many rounds, and in one of them I need to tp a random player to a random car. I'm afraid that it'll leave some players out, and repeat itself on other ones. I also need to put a feature in which if there are less than 3 players, the round wil not start. Here is the code: (Notice is the GUI it works)

local notice = game.Lighting.Notice
while true do
notice.Value = "Sled Race!"
pos = -233, 2.9, 136 
dft = {} 

function GetPlayers()
local c = game.Players:GetChildren() 
for i = 1, #c do 
table.insert(dft, c[i].Name) 
end 
end

function Randomize()
GetPlayers()
local d = math.random(1, #dft) 
local s = d 
local m = Instance.new("Message", game.Workspace) 
m.Text = "" 
wait(2) 
m:Remove()
local rndm = game.Players:FindFirstChild(dft[s])
if (rndm ~= nil) then 
local Player = rndm.Character
Player:MoveTo(Vector3.new(-233, 2.9, 136))
end
end

wait(2)
Randomize()
wait (30)
end

1 answer

Log in to vote
0
Answered by
Aespect 25
10 years ago

I don't quite understand the question, but I think this will help?

    local notice = game.Lighting.Notice
while true do
notice.Value = "Sled Race!"
pos = -233, 2.9, 136

function Randomize()
local plrs = game.Players:GetChildren()
local rndm = plrs[math.random(1,#plrs)]
local m = Instance.new("Message", game.Workspace) 
m.Text = "The random player chosen was "..rndm.Name 
wait(2) 
m:Remove()
if rndm then 
local char = workspace:FindFirstChild(rndm.Name)
char.Torso.CFrame = CFrame.new(pos)
end
end

wait(2)
if game.Players.NumPlayers<3 then
    repeat wait() until game.Players.NumPlayers>= 3
    if game.Players.NumPlayers>=3 then
        wait()
    end
end
Randomize()
wait (30)
end
Ad

Answer this question