Based on what you asked, you may want to use a server script (not LocalScript) for that:
game.Players[name_of_the_player].leaderstats.money.Value = i
That should be wrapped in a function that connects to an event when the bricks reached the end of the conveyor.
In case if you want it to change in a LocalScript, you can learn how to do the same method using Remote Functions and Events.
Sorry if I'm answering this in a rush. Tell me if you want more info, or wait for others to answer.
EDIT:
Imagine you have some tycoons, each tycoon only has one owner.
This is not the most convenient method to get the player, but it works.
Step 1: Create your own Teams. You can add teams manually in Studio, right to the bottom of the Explorer (the icon of a football). Each teams should have a unique color (and name) of their own.
Step 2: Make sure that only ONE (you can extend the limit if you wish) player can be a part of a team, and cannot change teams after choosing a team or be teammates of other teams that already have a player. The player limit of your game is recommended to be restricted to the number of teams you have. The number of teams of your game will have to be relative to the number of tycoons in the game.
References:
Team class
Player.TeamColor
SpawnLocation (if you plan to use this for the players to change teams, it is useful in some cases)
Step 3: Get the players of the specified team using Team:GetPlayers(). Note that this returns an array of objects represent as members of the team, so you have to index it.
local teams = game.Teams
local team = teams.NameOfYourTeam
local plrs = team:GetPlayers()
table.foreach(plrs, function(key,value)
if value:IsA("Player") then
value.leaderstats.money.Value = value.leaderstats.money.Value+1
end
end)
table.foreach() executes a function on each member of the table (array) it got. It's pretty much the same as for i, p in pairs(plrs) do end.
Step 4: Change the player's leaderboard stats
You can use the method I written above combined with how to assign values to the leaderboard and sum them up into a function. Once done, connect the function to an event that fires every time the blocks reached the end of the conveyor. You can use the .Touched event.
Now, it's time for you to explore with some trial and error on your own! There are plenty of methods to do this.
3 comments
so what I am confused about is what do i put for [name_of_the_player] because I tested is by putting in my username and it worked, but obviously I can't type in the name of every player on roblox
Make sure you're inputting a string. You should have the sell part (the part that gives money when touched by an ore) find a Model ancestor that has a special keyword that allows a script to pick out the plot's owner. Then you can use the plot owner's name in the Players service to access their leaderstats (via string key / findfirstchild).
@emrek, I edited the post to answer your question. You can also use game.Players:GetPlayers() and then use a for loop (or table.foreach, as shown) to take action on every players. For a single player alone, use the method above, or create an ObjectValue for each tycoons where the Value of it should be the Player object. Ask me, or others, especially the guy above me if you want more help c: