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

how do I change values on a leader board?

Asked by
emrek 7
5 years ago

So I am making a tycoon game and I can't figure out how to change the values on a leader board. Every time a part that drops from a dropper should give money to the player when it reaches the end of the conveyor belt. If I learn how to do this then I should be able to do other things like make it so players can buy other droppers and have that money taken away. I have a script that makes the leader board and this is what it looks like.>

local function onPlayerJoin(player)
    local leaderstats=Instance.new("Folder")
    leaderstats.Name="leaderstats"
    leaderstats.Parent=player
    local money=Instance.new("IntValue")
    money.Name="money"
    money.Parent=leaderstats
    money.Value=0
end

game.Players.PlayerAdded:Connect(onPlayerJoin)

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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 --Where i is the preferred value for the leaderstats of the specified player

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.

--Getting the player of the team (That only has one member)
local teams = game.Teams
local team = teams.NameOfYourTeam --imagine this is the team you want to check

local plrs = team:GetPlayers() --returns a bunch of players in the team (but in this case, we only get one, but it's still in an array, so we have to get it using table.foreach() since I really like using it

--You can also use for loop for this one but ohwell
table.foreach(plrs, function(key,value)
    if value:IsA("Player") then --is this a player?
        --the variable "value" represents the player you want to take action on.
        --From this part, do something
        --This will be an example.
        value.leaderstats.money.Value = value.leaderstats.money.Value+1 --adds a piece of penny to the player's stats
    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.

0
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 emrek 7 — 5y
0
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). Fifkee 2017 — 5y
0
@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: Afterl1ght 321 — 5y
Ad

Answer this question