I've made a datastore script to save rebirths, coins and gems. I get no errors (yey) but it just doesnt save (not yey). I have API services turned on and am testing it via roblox.com not studio. I must be doing smth wrong eh? cheers for the help if any.
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")
local function onPlayerJoin(Player)
local leaderstats = Instance.new("Folder", Player)
leaderstats.Name = "leaderstats"
local val1 = Instance.new("StringValue",Player)
val1.Name = 'GotPet'
val1.Value = ''
local val2 = Instance.new("StringValue",Player)
val2.Name = 'OpenValue'
val2.Value = ''
local Gems = Instance.new("IntValue", leaderstats)
Gems.Name = "Gems"
Gems.Value = 0
local Rebirths = Instance.new("IntValue", leaderstats)
Rebirths.Name = "Rebirths"
Rebirths.Value = 0
local Coins = Instance.new("IntValue", leaderstats)
Coins.Name = "Coins"
Coins.Value = 0
local playerUserId = "Player_" .. Player.UserId --Gets player ID
local data = playerData:GetAsync(playerUserId) --Checks if player has stored data
if data then
print("Data found!")
-- Data exists for this player
Coins.Value = data
Rebirths.Value = data
Gems.Value = data
else
print("DataStore working but No data found")
-- Data store is working, but no current data for this player
Coins.Value = 0
Rebirths.Value = 0
Gems.Value = 0
end
end
local function onPlayerExit(player) --Runs when players exit
local success, error = pcall(function()
print("Data loaded successfully")
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player.leaderstats.Coins.Value)
playerData:SetAsync(playerUserId, player.leaderstats.Rebirths.Value)
playerData:SetAsync(playerUserId, player.leaderstats.Gems.Value)--Saves player data
end)
if not success then
warn('Could not save data!')
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)

2 comments
Doesnt seem to be working..
This script could be interfering? https://pastebin.com/5jQLyMmz (its what i use to 'test' the datastore/leaderstats, basically just enter the code "Welcome" and you get coins, i then log out and log back in. the money doesnt save)