I have been trying to make a random player picker then if they are picked they will be teleported do you know how to do it?
✓ ANSWER ACCEPTED
How do you make a random player picker than make them teleport if picked?
2 answers
✓ Accepted answer
local Players = game:GetService("Players"):GetPlayers()
local SelectedPlayer = Players[math.random(1,#Players)]
local Character = SelectedPlayer.Character or SelectedPlayer.CharacterAdded:Wait()
Character:SetPrimaryPartCFrame(workspace.Part.CFrame)
You could maybe insert a table with all the players inserted into it and randomly pick the index
local PlayerTable = {}
game.Players.PlayerAdded:Connect(function(plr)
table.insert(PlayerTable, plr.Name)
end)
Now, the way to pick out a random index from this table would be like this (adding on to the previous script)
local PlayerTable = {}
local playersInGame = game.Workspace.IntValue --//You could create an IntValue somewhere for example workspace to see how many players are in the game
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(plr)
table.insert(PlayerTable, plr.Name)
playersInGame.Value = playersInGame.Value + 1
end)
game.Players.PlayerRemoving:Connect(function(plr)
playersInGame.Value = playersInGame.Value - 1
for i,v in pairs (PlayerTable) do
if v == plr.Name then
table.remove[i] --//Will remove the player on that index
end
end
end)
--//Code e.g.
game.Workspace.Part.Touched:Connect(function()
local RandomNum = math.random(1,playersInGame.Value)
for i,v in pairs (PlayerTable) do
if i == RandomNum.Value then
print(v) --//Will print out the random player's name
--//From here you can do anything like
local selectedPlayer = Players:FindFirstChild(v)
selectedPlayer.Character:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(game.Workspace.Part.Position + Vector3.new(0,3,0))
end
end
end)
This line game.Workspace.Part.Position is any part you want to teleport the player to. You will need to make a part that you want to teleport the player to.
If you don't want the player to see the part then, you can make it invisible by setting transparency to 1
I'm sorry if this won't work i am not that experienced but i always do the best i can. If you need any more explaining or you don't understand something, you may ask for help
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Show us your code please.