If anyone viewing has a similar issue, we talked it over over discord and came up with this solution:
Comments are there explaining what each bit of code does, but comment if you need anymore explanation.
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local epicnessDatastore = DataStoreService:GetDataStore( "EpicnessDatastore" ) |
06 | function onPlayerJoin(player) |
08 | local leaderstats = Instance.new( "Folder" ) |
09 | leaderstats.Name = "leaderstats" |
10 | leaderstats.Parent = player |
12 | local Epicness = Instance.new( "IntValue" ) |
13 | Epicness.Name = "Epicness" |
15 | Epicness.Parent = leaderstats |
21 | local success, epicness = pcall ( function () |
22 | return epicnessDatastore:GetAsync(player.UserId) |
28 | player.leaderstats.Epicness.Value = epicness |
32 | function onPlayerRemoving(player) |
33 | print (player.Name .. " has left the game!" ) |
36 | local success, err = pcall ( function () |
37 | epicnessDatastore:SetAsync(player.UserId, player.leaderstats.Epicness.Value) |
41 | game.Players.PlayerAdded:Connect(onPlayerJoin) |
42 | game.Players.PlayerRemoving:Connect(onPlayerRemoving) |