✓ Accepted answer
Most scripters opt against storing values in instances:
Storing values in the player: good or bad
Instead, values are contained within code keyed on the player's ID/Name:
Server Script
local userData = {}
local players = game:GetService("Players")
local function joined(player)
userData[player.Name] = {
["Items"] = {};
["Coins"] = 0
}
userData[player.Name].Items = {"item1", "item2", "item6"}
userData[player.Name].Coins = 500
end
players.PlayerRemoving:Connect(function(player)
userData[player.Name] = nil
end)
players.PlayerAdded:Connect(joined)
You can then easily use userData to access any user data you've defined all from one place. You can even turn it into a module script and return specified values as-needed which are up-to-date. If the client needs the information, then simply send the information over using a remote. I hope this helps, I tried to be as informative as possible
3 comments
Oh wow This is really helpful for me!!! Im going to use this method instead. Im also going to use it for DataStores! Thank you so much! Have a great day!
Yeah data store methods are much better! :) You can make your own (there's a great tutorial in the guides section) or you can try DataStore2 which you can download/get from the workshop :)
No problem at all! You're absolutely right to use this for DataStores since it's a partial example of caching the data.