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

How do I make this so that whenever a person enters, they receive a weapon?

Asked by 7 years ago
Edited 7 years ago
function onPlayerAdded(players)
    for -- I don't know what else to do?
game.Lighting[script.Parent.Name]:Clone().Parent = players[i].Backpack
game.Lighting[script.Parent.Name]:Clone().Parent = players[i].StarterGear

    end
    end

It's not in starter pack because I made a GUI where when you press a textbutton with a weapon's name on it, it will generate that weapon and put it in everyone's backpack and startergear. But I want it so that when other people join the server, they get the weapons as well.

Here's the script that generates a weapon when someone clicks the GUI, for some reason for i,v players do doesn't give the players a weapon, it only gives whoever clicks the GUI a weapon

script.Parent.MouseButton1Click:connect(function()  
local players = game.Players:GetChildren()
for i = 1, #players do
game.Lighting[script.Parent.Name]:Clone().Parent = players[i].Backpack
game.Lighting[script.Parent.Name]:Clone().Parent = players[i].StarterGear
onPlayerAdded()


end
end)

0
for i, v in pairs(players) do DeveloperSolo 370 — 7y
0
@JohnTUnderwood it breaks Willie3838 5 — 7y
0
right my bad. look below vvvvvvvvvv DeveloperSolo 370 — 7y

1 answer

Log in to vote
2
Answered by 7 years ago

First, don't store data in Lighting. Store it in ServerStorage (to make it so only the server can access it) or ReplicatedStorage (both the client and the server can access it).

Second, in onPlayerAdded, provided you connected it to game.Players.PlayerAdded, the variable "players" will only be the player who joined.

Therefore, no for loop is needed.

Instead, run the code you're already running but instead of players[i], use player.

0
This is the correct answer. AZDev 590 — 7y
0
Still doesn't work, it should but it doesn't Willie3838 5 — 7y
Ad

Answer this question