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

How to make it so someone is randomly chosen as kill and gets weapon and spawn others with a weapon?

Asked by 10 years ago

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?

3 answers

Log in to vote
0
Answered by
gkCode 10
10 years ago

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.

Ad
Log in to vote
0
Answered by 10 years ago

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.

0
thanks iiBrenton 0 — 10y
Log in to vote
-1
Answered by 10 years ago

1qwertyuiowertyuiop

0
ugh nub iiBrenton 0 — 10y
0
Calm down Roboy5857 20 — 10y
0
i rlly wanna know this :l iiBrenton 0 — 10y

Answer this question