Hidden leaderstats source code

Hi, Here I bring you a problem that I have, it is about creating a currency value without using the leaderstats so that they do not appear in the players table. I have a script that does that and also saves the progress but my question is how could I improve it. I also don’t know how I can do to change that data in game. I would like to be able to make a way to gain from that value with ProximityPrompt but I can’t. If you want to help me, I would really like it. Thank you so much

local DataStore = game:GetService("DataStoreService")
local Data1 = DataStore:GetDataStore("Data1")

game.Players.PlayerAdded:Connect(function(player)
	
	local folder = Instance.new("Folder", player)
	folder.Name = "coins_values"
	
	local chekpoint = Instance.new("IntValue", folder)
	chekpoint.Name = "coins"
	chekpoint.Value = Data1:GetAsync(player.UserId) or 1
	
	chekpoint.Changed:Connect(function()
		
		Data1:SetAsync(player.UserId, chekpoint.Value)
	end)
	
end)
game.Players.PlayerRemoving:Connect(function(player)
	
	Data1:SetAsync(player.UserId, player.coins_values.coins.Value)
	
	
end)

Am I right you want to give a player extra Coins if the player is pressing a proximitypromt?
You shouldnt ask for code but you could do something like this:

(not local script)

local proxP = ..

proxP.triggered:Connect(function(player)
wait()
player.coinsValues.Coins.Value += 20 --dont do a _ between them!
...
end)

...


I hope that it was helpful

Yes, I don’t like asking for a code but I couldn’t find a way to add points to the value. the same thanks but the code it saves is fine, I’m hardly good with datastore

1 Like
  1. Datastore methods such as :GetAsync() or :SetAsync() will occasionally fail so you should wrap them in a pcall

  2. Your using :SetAsync on a .Changed event for multiple players which will put heavy load unto the datastore from multiple calls so fast. You can fix this by simply just using :SetAsync() when the player leaves or have your datastore save all the players data in a 1 minute interval loop.

  3. Using the parent parameter in Instance.new(“Classname”, Parent) is slower than just setting the parent property after setting all the other properties. More info on that here

  4. You can do += on your points value to increase

Other than that the script is fine