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

How do I refer a player in a script?

Asked by 10 years ago

I am making a game called Agent Blox which is based on Juggernaut but how to I make a script that chooses a random player to be in another team (classname) I think there is a way I could fix that but I don't know how to refer to a player in a script! game.Players.Player does not work. Please help!

0
You forgot the Workspace in between game.Players. Roboy5857 20 — 10y
0
I have seen this question asked numerous times on SH, you should be able to search for the answer. Roboy5857's answer here is also *wrong* and to be ignored. BlueTaslem 18071 — 10y

3 answers

Log in to vote
0
Answered by 10 years ago

In the example I have done for you below, I start off with picking a variable for the TeamColor. Then I choose a random player by using math.random() with the minimum amount of players (1) to the number of players, which I can find by using "#game:GetService("Players"):GetPlayers()", or I could have done "game:GetService("Players").NumPlayers". Both work fine. Then I make that players TeamColor the BrickColor of the variable we provided earlier.

local TeamColor = "Really red"
local RandPlayer = game:GetService("Players"):GetPlayers()[1, #game:GetService("Players"):GetPlayers()]
RandPlayer.TeamColor = BrickColor.new(TeamColor)
Ad
Log in to vote
-1
Answered by
Hybric 271 Moderation Voter
10 years ago
local players = game.Players:GetChildren()
local log10 = math.random(1, #players)
players[log10].TeamColor = "Bright blue" -- Make Juggeranut team Bright blue
players[log10].Character:MoveTo(Vector3.new(0,0,0)) -- change 0,0,0 To a position the juggernaut will spawn.

PM Hybric if script doesn't work

1
It's BrickColor.new("Bright blue") not just "Bright blue". Archonious2 160 — 10y
0
Also he never specified for the player to be moved. Archonious2 160 — 10y
Log in to vote
-4
Answered by 10 years ago

This might not work but here you go.

game.Workspace.Players.Random = Random.Players

Probably try that in the script

0
This is not correct at all. Sublimus 992 — 10y
0
Well you can be a bit nicer. I tried. Roboy5857 20 — 10y
0
Don't post an answer if you have no idea what you're doing. That just spreads false information. User#11893 186 — 10y
0
Well thanks for information you already told people. I tried so you should give me that. Stop jumping on people for false information. God. Roboy5857 20 — 10y

Answer this question