I’m pretty new to coding and I’m trying to make a game similar to the normal elevator. I want to create a floor where a random player will be selected and it’ll play out a fight scene, the only problem is I’m not sure how I’d make it pick a random player and then make it play a animation that syncs up with the dummy. Any help would be appreciated!
It’s not too complicated.
- First is get the table of the players by game.Players:GetPlayers()
- Second, run a random function either by math.random() or Random.new(), you can see how it can be used on the internet.
- Thirt, get the number you’ve got and get the player in the table.
Here’s an exambple
local plrs = game.Players:GetPlayers()
-- I'm using Random.new() medthod
local RandomNumber = Random.new(os. time) -- the seed
RandomNumber:NextInteger(1, #plrs) -- the number of player
local ChosenPlr = plrs[RandomNumber]
-- the rest
1 Like
How would I make it teleport the player that was chosen to a certain spot?
Simply add
ChosenPlr.Character.PrimaryPart.Position = Vector3.new(69, 21, 420) -- replace with position to teleport to
Do you know how I would fix this error with the first part of the script?
Edit: Sorry I forgot to include the full code
Edit 2: Never mind I figured it out after checking some older dev posts
local plrs = game.Players:GetPlayers()
local RandomNumber = Random.new(os. time) -- the seed
RandomNumber:NextInteger(1, #plrs) -- the number of players
local ChosenPlr = plrs[RandomNumber]
ChosenPlr.Character.PrimaryPart.Position = Vector3.new(-150.25, -66.75, 104.5) -- teleport position
1 Like