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

Why is this giving everyone a weapon?

Asked by 9 years ago

So im trying to give one person a weapon, but its giving everyone a weapon when i start a test server in studio

1local choose = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())]
2 
3if choose:FindFirstChild("Backpack") then
4game.ReplicatedStorage.Luger:Clone().Parent = choose.Backpack;
5 
6end

EDIT

thats not all of it though,

01local players = game.Players:GetPlayers()
02local using = false
03 
04while math.huge do
05    wait(5)
06using = false
07if using == false then
08  using = true 
09    if (game.Players.NumPlayers <= 1) then -- This will be the less complicated 'invite more' part
10        using = true
11        game.StarterGui.gui.LocalScript.Event:Fire()
12    else
13    if(game.Players.NumPlayers >= 2) then
14        wait(5)
15 
View all 36 lines...

EDIT 2

It seems to be giving out a weapon per player, and sometimes gives someones weapon to another person

1 answer

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

This on its own shouldn't be giving every Player a weapon, although it can be optimized slightly:

1local choose = game.Players:GetPlayers()[math.random(game.Players.NumPlayers)]
2 
3if choose:FindFirstChild("Backpack") then
4    game.ReplicatedStorage.Luger:Clone().Parent = chose.Backpack;
5end

First, let's fix your formatting and take a better look at your code:

01local players = game.Players:GetPlayers()
02local using = false
03 
04while true do --No need to be fancy.
05    wait(5)
06    using = false
07    if using == false then
08        using = true   
09        if (game.Players.NumPlayers <= 1) then -- This will be the less complicated 'invite more' part
10            using = true
11            game.StarterGui.gui.LocalScript.Event:Fire()
12        else --The `if` here covered the *entire* other case, so an `else` works just fine on its onw.
13            --For future reference, `elseif` is a valid branch.
14            wait(5)
15 
View all 37 lines...
0
no, ill give it all bubbaman73 143 — 9y
0
(im still working on it so it doesnt delete the weapons yet) bubbaman73 143 — 9y
0
Thanks! Im new to looping a lot at things at once bubbaman73 143 — 9y
Ad

Answer this question