how do i script it so someone is randomly picked as the killer and is spawned away from the survivors with a weapon and than spawn others a few seconds after and they spawn with guns?
How to make it so someone is randomly chosen as kill and gets weapon and spawn others with a weapon?
3 answers
In the script it makes sure that there are atleast two people in the game. All you have to do is continue the script however you want, or add something in the beginning of the loop to lead up to the game:
TableOfPlayers = {}
game.Players.PlayerAdded:connect(function(Player)
table.insert(TableOfPlayers, Player.Name)
print(TableOfPlayers[1])
end)
while true do
if game.Players.NumPlayers >= 2 then
while true do
wait(1)
RandomValue = math.random(1, table.getn(TableOfPlayers))
wait()
RandomPlayerName = TableOfPlayers[RandomValue]
wait()
Hint = Instance.new("Hint")
Hint.Parent = Workspace
Hint.Text = RandomPlayerName.." has been chosen as the killer!"
wait(4)
Hint.Text = "Teleporting all players to the map..."
RandomPlayer = game.Players:FindFirstChild(RandomPlayerName)
if RandomPlayer then
RandomPlayer.Character.Torso.CFrame = CFrame.new(...)
wait(5)
for i, v in pairs(game.Players:GetPlayers()) do
if v.Name ~= RandomPlayer.Name then
v.Character.Torso.CFrame = CFrame.new(...)
wait()
end
end
Hint.Text = "Giving gun to the killer..."
KillerGun = game.Lighting.KillerGun
KillerGunClone = KillerGun:Clone()
KillerGunClone.Parent = RandomPlayer.Character
wait(3)
Hint.Text = "Giving guns to the players..."
for i, v in pairs(game.Players:GetPlayers()) do
if v.Name ~= RandomPlayer.Name then
PlayerGun = game.Lighting.PlayerGun
PlayerGunClone = PlayerGun:Clone()
PlayerGunClone.Parent = v.Character
wait()
end
end
wait(5)
else
Hint.Text = "The killer has left. Reseting game."
wait(4)
Hint:remove()
end
end
else
Hint1 = Instance.new("Hint")
Hint1.Parent = Workspace
Hint1.Text = "Sorry, we need 2 players to begin the game."
while wait() do
if game.Players.NumPlayers >= 2 then
Hint1:remove()
break
end
end
end
wait()
end
You can change the names of the guns as well. Also change where the killer teleports and where the people teleport.
In this code there is no part that concludes the game, such as when the people are eliminated or if the killer is killed. All this script does is chooses someone at random, gives them a gun, and teleports them somewhere. The other players are also teleported somewhere and given guns.
Hope this helps! Message me, gkCode, if you have any questions.
You may want to try a script like this:
p = game.Players:GetChildren
num = math.random(1, #p)
for i,v in ipairs(p) do
if i == num then
v = "Killer"
else
v = "Not Killer"
end
end
It sets a number to each player, and then chooses a random number. If that player's number is chosen, then that player is the killer.
1qwertyuiowertyuiop
3 comments
ugh nub
Calm down
i rlly wanna know this :l
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
thanks