Hello I am new to Lua and I know very little now with this script, what I am trying to do is make a script that randomizes each players weapon, for example lets say theres 4 players in my game, then each one of them will recieve a different weapon that was stored in lighting, heres the script, also when I try playing solo my character won´t appear in that place.
game.Players.PlayerAdded:connect(function(p) p.CharacterAdded:connect(function(c) repeat wait() until p:FindFirstChild("Backpack") game.Lighting:GetChildren()[math.random(1, #game.Lighting:GetChildren())]:clone().Parent = p.Backpack end) wait(2) end)
Roblox does has some glitches and stuff like this happens to me a lot! Try putting the code in a new place (I don't see anything wrong with the code) and run it. If this does not work, I am baffled.
Here, try this. Put all the weapons in ServerStorage, it's the best place to put them.
game.Players.PlayerAdded:connect(function(p) local tools = {game.ServerStorage.tool1:Clone(), game.ServerStorage.tool2:Clone(), game.ServerStorage.tool3:Clone(), game.ServerStorage.tool4:Clone()} local randTool = tools[math.random(#tools)] if p:FindFirstChild("BackPack") then --backpack isnt part of character it's in the player randTool.Parent = p.BackPack end end)
That should work! Comment if it didn't.
The player added event does not fire in solo mode because the player is created before any scripts with playeradded run. If you really want to test this in solo mode add this to the end of your script.
for _, player in pairs(game.Players:GetPlayers()) do PlayerAdded(player) -- Use your player added handling function here. end
Alternatively you can start a local server (f7) and then start players (alt + f7).