So I had made a script that saved an intvalue value, but I wanted to add more than one value, but the way I had done it I couldn’t do it so I had to modify it. My problem is that after having modified it now it doesn’t work (there are no errors present in the output).
Here is the script:
local DataStoreService = game:GetService(“DataStoreService”)
local PlayerData = DataStoreService:GetDataStore(“PlayerDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local playerUserId = player.UserId
local data
local success, erro = pcall(function()
data = PlayerData:GetAsync(playerUserId)
end)
if success then
player.DataStore.Coin1.Value = data.Squiders
player.DataStore.Coins2.Value = data.Tixers
else
print(“error”)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = player.UserId
local data = {
Coin1 = player.DataStore.Coin1.Value;
Coin2 = player.DataStore.Coin2.Value;
}
local sucess,erro = pcall(function()
PlayerData:SetAsync(playerUserId, data)
end)
if sucess then
print("saved")
else
print("not saved")
end
seems like you are doing different variable names, at the PlayerAdded section you are getting data.Squiders and data.Tixers, while at the PlayerRemoving section you are saving these values as Coin1 and Coin2 not Squiders and Tixers
Try this:
local DataStoreService = game:GetService(“DataStoreService”)
local PlayerData = DataStoreService:GetDataStore(“PlayerDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local playerUserId = player.UserId
local data
local success, erro = pcall(function()
data = PlayerData:GetAsync(playerUserId)
end)
if success then
player.DataStore.Coin1.Value = data.Squiders
player.DataStore.Coins2.Value = data.Tixers
else
print(“error”)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = player.UserId
local data = {}
data.Squiders = player.DataStore.Coin1.Value
data.Tixers = player.DataStore.Coin2.Value
local sucess,error = pcall(function()
PlayerData:SetAsync(playerUserId, data)
end)
if sucess then
print("saved")
else
print("not saved")
end
end)
Try adding a print("END OF CODE") at the end of PlayerRemoving and see if it even reaches the end of the code, try doing same thing to the PlayerAdding too
Also if you are testing in studio make sure studio has access to API services through game settings
Do you create the player.DataStore.Coin1 and the other variable BEFORE loading? maybe the script tries to load into these variables before they are even created, try inserting the script that creates these folders and values into this script, here is a tutorial on doing DataStores: https://www.youtube.com/watch?v=DkYupSBUpes