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)
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
.