I'm trying to make this script give out cash to everyone when owner joins the game.
1 | for i, v in pairs (game.Players:GetPlayers()) do -- gets all the players |
2 | if v.Name = = "A1exTatum" then -- finds the owner |
3 | v.leaderstats.Cash.Value = v.leaderstats.Cash.Value + 20 -- gives out cash |
4 |
5 | end |
6 | end |
I would personally use your UserId, but the name works as well.
1 | game.Players.PlayerAdded:Connect( function (plr) --Detects when a player joins |
2 | if plr.Name = = "A1exTatum" then --Checks if their name matches yours... |
3 | plr:WaitForChild( "leaderstats" ):WaitForChild( "Cash" ).Value = plr.leaderstats.Cash.Value + 20 --Gives you the money |
4 | end |
5 | end ) |
You would need to make the function run upon a player joining.
1 | game.Players.PlayerAdded:Connect( function (player) |
2 | --anything here would run when a player joins |
3 | end ) |