So this is my tool give to players when they spawn (it randomizes). How do I make it where it gives it to the player when they join the game? It doesn't give it to them at all when they first join.
01 | game.Players.PlayerAdded:connect( function (p) |
02 | p.CharacterAdded:connect( function (c) |
03 | repeat |
04 | wait() |
05 | until p:FindFirstChild( "Backpack" ) |
06 | local clone = game.Lighting.WEAPONS:GetChildren() [ math.random( 1 , #game.Lighting.WEAPONS:GetChildren()) ] :clone() |
07 | clone.Parent = p.Backpack |
08 | c:WaitForChild( "1" ).Value = clone.Name |
09 | end ) |
10 | wait( 2 ) |
11 | end ) |
01 | local weapons = game.ReplicatedStorage.Weapons |
02 | function findRandomChild(model) |
03 | if #model:GetChildren() ~ = 0 then |
04 | local children = model:GetChildren() |
05 | local child = children [ math.random( 1 ,#children) ] |
06 | return child |
07 | end |
08 | end |
09 | game.Players.PlayerAdded:Connect( function (plr) |
10 | plr.CharacterAdded:Connect( function (char) |
11 | local weapon = findRandomChild(weapons) |
12 | plr:WaitForChild( 'Backpack' , 10000 ) |
13 | weapon:Clone().Parent = plr.Backpack |
14 | end ) |
15 | end ) |
Try this.