Hey, I'm new to scripting and would like to know how to make a leaderboard or leaderstats thats filter enabled so everyone will be able to see when a value change.
I've tried the code below from the wiki, but I want know how to make it so when you click on a text button your "Cash" will increase and other people will see it.
Also is there any easier way to filter enabled a leaderboard other than the one shown below? Thank you for your time. xd
ps. what are those brackets "[]" for and "_, player" mean.
-- Table for holding each player's 'leaderstat' values local playerLeaderStats = {} -- Function that executes when a player is added to the game game.Players.PlayerAdded:connect( function(player) playerLeaderStats[player] = {} -- Add a sub-table for the player to the 'playerLeaderStats' table playerLeaderStats[player]["Money"] = 0 -- Add a 'Money' key with value of 0 local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player -- Parent the 'leaderstats' object to the player local money = Instance.new("IntValue") -- Create a new 'IntValue' money.Name = "Money" -- The name of the in-game leader stat money.Value = playerLeaderStats[player]["Money"] money.Parent = leaderstats -- Set the money object as a child of the 'leaderstats' object end ) while wait(5) do for _, player in ipairs(game.Players:GetPlayers()) do if player:FindFirstChild("leaderstats") then -- Don't use the 'IntValue' value because an exploiter can modify it! playerLeaderStats[player]["Money"] = playerLeaderStats[player]["Money"] + 1 player.leaderstats.Money.Value = playerLeaderStats[player]["Money"] end end end
The wiki makes it kind of difficult to learn Filtering Enabled, that is why these questions arise so often.
I'm assuming this is a script from the wiki itself already and you are a intermediate to lua.
When Filtering is enabled in your game, it makes exploiters do whatever they do not replicate to the server from the client. A remote event/function has to be called to replicate to the server. So if they deleted the map, it'd only delete for them and not everyone else. Without FE enabled, the client will replicate to the server, causing whatever they do to appear for all players on the server.
The wiki goes more in-deph on this concept; link
Though when you have a script on the server side, it doesn't entirely need to be optimized for Filtering Enabled unless you are changing variables from the client. If you do want to accomplish that, it'd have to be protected since exploiters can find your events and fire them from the client to give themselves stats like Money.
If you plan on changing values from the client, I'd learn about RemoteEvents/Functions first: link or link
The "_,player" is a for loop, which you can learn about here; link
And, the "[]" are for indexing in tables. This was a question before and answered better than I could ever have; link
If this helped you in any way, I'd be nice to accept this answer! :D