So while I was testing my game, I noticed that these DataStores won't work. I had tested it a lot not on Studio, but with different alt. accounts for DataStore testing. Can someone tell me what's wrong with this script?
local dataStores = game:GetService("DataStoreService"):GetDataStore("BitsDataStore")
local defaultBits = 0
local playersLeft = 0
game.Players.PlayerAdded:Connect(function(player)
playersLeft = playersLeft + 1
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local bits = Instance.new("IntValue")
bits.Name = "Bits"
bits.Value = 0
bits.Parent = leaderstats
player.CharacterAdded:Connect(function(character)
character.Humanoid.WalkSpeed = 16
character.Humanoid.Died:Connect(function()
-- Whenever someone dies, this event will run
if character.Humanoid and character.Humanoid:FindFirstChild("creator") then
game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).." KILLED "..player.Name
end
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
player:LoadCharacter()
end)
end)
-- Data stores
local player_data
pcall(function()
player_data = dataStores:GetAsync(player.UserId.."-Bits") -- 1736284-Bucks
end)
if player_data ~= nil then
-- Player has saved data, load it in
bits.Value = player_data
else
-- New player
bits.Value = defaultBits
end
end)
local bindableEvent = Instance.new("BindableEvent")
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
dataStores:SetAsync(player.UserId.."-Bits",player.leaderstats.bits.Value)
print("Saved")
playersLeft = playersLeft - 1
bindableEvent:Fire()
end)
end)
game:BindToClose(function()
-- This will be triggered upon shutdown
while playersLeft > 0 do
bindableEvent.Event:Wait()
end
end)

4 comments
what did i say about watching alvinbloxx
I heard there is a DataStore problem on Roblox, and there is no solution yet. Roblox has been very transparent about this. It's on their top priority to fix DataStores.
Oh, ok! Didn't knew that there is a DataStore problem.
and incapaxx is not my dad