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

[Solved] How would i go by making this script give out cash when owner joins game?

Asked by 4 years ago
Edited 4 years ago

I'm trying to make this script give out cash to everyone when owner joins the game.

for i, v in pairs(game.Players:GetPlayers()) do  -- gets all the players
if v.Name == "A1exTatum" then  -- finds the owner
v.leaderstats.Cash.Value = v.leaderstats.Cash.Value + 20  -- gives out cash

end
end

2 answers

Log in to vote
3
Answered by 4 years ago

I would personally use your UserId, but the name works as well.

game.Players.PlayerAdded:Connect(function(plr) --Detects when a player joins
    if plr.Name == "A1exTatum" then --Checks if their name matches yours...
        plr:WaitForChild("leaderstats"):WaitForChild("Cash").Value = plr.leaderstats.Cash.Value + 20 --Gives you the money
    end
end)

1
regular script or, local? i would assume regular but, just making sure A1exTatum 57 — 4y
1
Nvm got it working, Thanks! A1exTatum 57 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You would need to make the function run upon a player joining.

game.Players.PlayerAdded:Connect(function(player)
  --anything here would run when a player joins
end)
0
You'd also need to add an if-statement to see if the player name (or user id) is the same as the owner's player name. blarp_blurp645 63 — 4y

Answer this question