Hi! You could make use of DataStores. They basically save data to a DataStore in your place that can be accessed at any time (just not via command bar without a key). You could view more about it from this article or I could explain it really quickly if you’d like. So depending on how your system is set up, you would have to modify it - the main thing is that you understand how it works. So to set up a DataStore you would just add these two lines to the start of every script that requires access to it:
local DSS = game:GetService("DataStoreService")
local DonorStore = DSS:GetDataStore("DonorStore")
This would basically allow you to store values into keys within that DataStore. Then, to save their donation (not the Robux just the information) to it, you could do something like this:
local DSS = game:GetService("DataStoreService")
local DonorStore = DSS:GetDataStore("DonorStore")
local function donate(donor,amount)
local ID = donor.UserId -- You could also use game.Players:GetUserIdFromNameAsync()
DonorStore:SetAsync(ID,tonumber(amount))
end
game.Players.PlayerAdded:Connect(function(plr)
donate(plr,amount) --Call this function when they donate.
end)
That would be a basic idea of how to save their donation information to the server. If you do not need the amount they donated then you could just remove that. tonumber()
was used because if you extracted their amount from a TextLabel, you would need to convert it to a number before saving it (so that you can add to it when necessary). Now to display their donor status, you could do something like:
local DSS = game:GetService("DataStoreService")
local DonorStore = DSS:GetDataStore("DonorStore")
game.Players.PlayerAdded:Connect(function(plr)
local AmountDonated = DonorStore:GetAsync(plr.UserId)
if AmountDonated > 0 then
--Give them their donor perks, tag, title or whichever.
end
end)
All this is just a rough idea, but there are many more precautions you would need to take when using DataStores. For instance, they tend to fail occasionally - especially if too many requests are sent at once or if tables are being stores. To prevent the rest of our script from breaking, we can make use of pcall()
. A protected call will ensure that any error returned by a function will stay within the pcall()
, and you would be able to work from there. For example:
local success,fail = pcall(function()
local AmountDonated = DonorStore:GetAsync(plr.UserId)
end)
if success then --Checks if success returns the boolean 'true'.
if AmountDonated > 0 then
--Give them their donor perks, tag, title or whichever.
end
else
--Let the player know that their donor title has not loaded.
end
This would be the most convenient and efficient approach in my opinion, however if you have no prior experience to handling DataStores you may need to experiment around a lot with them haha. Good luck!