DataStore won't work at all

Personally, I think the issue is that your players aren’t being registered at all. If you truly aren’t getting errors (check your console again) and you know you have all the game configurations set (DataStores do not need HttpEnabled), this is the only thing I can think of. Combat it using a catcher function. Essentially: take the anonymous function that listens to PlayerAdded and make it a defined function. Have it listen to PlayerAdded then run it on existing players.

local Players = game:GetService("Players")
-- DataStores up here, you should know how to move them over

local function playerAdded(player)
    -- All your PlayerAdded code here; I'm not filling it in for you
end

-- Might as well stick to new conventions and make things readable
local function playerRemoving(player)
    -- Your PlayerRemoving code here; I'm not filling it in for you
end

Players.PlayerAdded:Connect(playerAdded)
Players.PlayerRemoving:Connect(playerRemoving)

for _, player in pairs(Players:GetPlayers()) do
    playerAdded(player)
end

Some other recommendations, besides this, to make.

  • Look into using only a single DataStore for all player data instead of one per stat. Having two DataStores for each player can result in any of the following consequences: unreadability, maintenance trouble, data loss, throttled/hogged DataStore requests, et cetera.

  • Don’t use the parent argument with Instance.new, considering you set properties (even if it is just one) after instancing. Create the instance, name it then parent it.

  • You aren’t making good use of pcalls. One pcall should be responsible for wrapping one call, not several of them. Furthermore, the creation of the upvalues data1 and data2 is unnecessary; you can return the result of GetAsync or wrap the function directly.

  • Your data script should not be assuming that if the pcall is successful, then it’s clear to add data. If a player doesn’t have data stored, your script is setting the values of some ValueObjects to nil. That’s a no-no. Cannot hardset nil just because a call passes.


@serverModule It’s not. The indenting may be bad but you can pretty clearly see that PlayerRemoving is outside of the PlayerAdded function. Despite this, it wouldn’t make a difference.

1 Like