This would be a normal leaderstats script:
--\\ Services local players = game:GetService("Players") players.PlayerAdded:Connect(function(player) local stats = Instance.new("Folder") stats.Name = "leaderstats" stats.Parent = player local randomValue = Instance.new("StringValue") randomValue.Name = "Random Value" randomValue.Value = "oof" randomValue.Parent = stats end)
I noticed, is this really the best way to make stats? Is there an even more secure(and probably optimized way). I am saying if there is a much more secure way to approach this because it doesn't even use any Remotes. I am just curious to see if there are any different (and probably better) approaches.
Thank you for helping me in advance
you should make a folder in server storage call it stats then do this in your script
you willalso have to change 2 values when changing the leaderstats and there can not be a wait() between the two lines also they should look like this
player.leaderstats["Random Value"].Value = "Hi"
game.ServerStorage.Stats[player.Name]["Random Value"].Value = "Hi"
local players = game:GetService("Players") players.PlayerAdded:Connect(function(player) local Folder = Instance.new("Folder", game.ServerStorage.Stats) Folder.Name = player.Name local stats = Instance.new("Folder", game.ServerStorage.Stats[player.Name]) stats.Name = "leaderstats" local randomValue = Instance.new("StringValue", stats)--same thing as randomValue.Parent = stats randomValue.Name = "Random Value" randomValue.Value = "oof" end) while true do wait() for i,v in pairs(players:GetChildren()) do if v.leaderstats["Random Value"].Value ~= game.ServerStorage.Stats[v.Name]["Random Value"] then -- for this ill just kick them kick(v, "Stop Hacking") end end
This would be secure if you turned on FilteringEnabled, only if you don't make a RemoteEvent that lets the client change the folder. I don't recommend that you allow the client to change the folder, because then exploiters can just fire the remote and cheat. You could make add an extra argument for a password, but that doesn't really help much since exploiters can just listen for every time the remote is fired then copy and paste the arguments. If you really wanted the client to change the folder, then you can make a remote that does something specific that changes the folder. An example: Imagine your folder had a value inside called Knockouts. Making a remote for increasing the value wouldn't be secure at all, but making a remote that shoots a bullet at a position is very secure, because if an exploiter fired the remote, they would just be playing normally, just by using scripts.
Hope this helped!
PS: I don't really think there's a better way to do it.