#datastoreservice script not working
1 messages · Page 1 of 1 (latest)
not working how so?
it's just like
it keeps saying error-type when i hover over it
like it's not detecting it
as an actual statement
https://create.roblox.com/docs/reference/engine/classes/Player#UserId
Are you grabbing it from the player, and are you doing userid or UserId
no that's how i have my code
it's in leaderboardsetup
here just
local Players = game:GetService("Players")
local playerChar = Players:GetPlayerFromCharacter(Players)
local backpack = Players:FindFirstChildOfClass("Backpack")
local SS = game:GetService("Studio")
-- Datastore service
local DSS = game:GetService("DataStoreService")
local playerInv = DSS:GetDataStore("playerInventory")
local playerStars = DSS:GetDataStore("playerInventory", "Stars")
local playerBackpack = DSS:GetDataStore("playerInventory", backpack)
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Stars = Instance.new("IntValue")
Stars.Name = "Stars"
Stars.Value = 0
Stars.Parent = leaderstats
local success, starsAmount = pcall(function()
return playerStars:GetAsync(player.UserId)
end)
end
Players.PlayerAdded:Connect(leaderboardSetup)
and you're getting errors in the output?
hmm well i can try it's just
it wasn't autofilling (not with the ai i mean when you're writing and it has the list of different statements) so i just assumed it wasn't going to work bc it does that to me
let me see
waaaait
i forgot to enable api one sec
nah no nvm no errors
you're not really doing anything with starsAmount after you load it
Okay, but all's good otherwise?
yeah i'm alr dw i can figure this out
can you print(playerStars) for me
wondering if thats causing your issue
i am under the belief you cant do "playerInventory", "Stars"
aka only takes one arguement being playerinventory
then you do playerinventory.Stars
since i assume its inside right
** You are now Level 4! **
wait idk wait one sec
nahh says stars isn't a valid ,member of player ivnneoyty
inventory
Try getting only the player inventory
Then print it
See what's inside
If Stars is inside you can access stars from it
nah it says only the player inventory
like that just in the output
ok let me screnshot hold on
here's the sdcript i wrote
local Players = game:GetService("Players")
local backpack = Players:FindFirstChildOfClass("Backpack")
-- Datastore service
local DSS = game:GetService("DataStoreService")
local playerInv = DSS:GetDataStore("playerInventory")
local playerStars = DSS:GetDataStore("playerInventory", "Stars")
local playerBackpack = DSS:GetDataStore("Backpack", backpack)
print(playerInv)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Stars = Instance.new("IntValue")
Stars.Name = "Stars"
Stars.Value = 0
Stars.Parent = leaderstats
local success, starsAmount = pcall(function()
return playerStars:GetAsync("Stars", player.UserId)
end)
if success then
Stars.Value = starsAmount
print("playerStars retrieved")
print(starsAmount)
else
Stars.Value = 0
end
local success, errorMessage = pcall(function()
return playerBackpack:GetAsync("playerBackpack", player.UserId)
end)
if success then
player.Backpack = playerBackpack
else
print("Refreshed due to an error.")
end
end)
but the issue i'm having now is that
player data is not being retrieved at all
like the currency resets back the 0
also i keep getting the error messsage i wrote for trying to retrieve the player's backpack
i think i wrote smthn wrong
if so can some1 pls help and explain what i did wring
wrong*
datastoreservice script not working
My boy
GetDataStore
You can't do GetDataStore("playerinventory",Stars)
Or like how you did backpack
local playerStars = DSS:GetDataStore("playerStars")
local playerBackpack = DSS:GetDataStore("playerBackpack")
If must be one arguement
The second optional parameter is for scope keys
You do the same thing with GetAsync("Stars",player.UserId)
Your passing two arguments when it only takes one
okay so if i am understanding correctly i can do DSS:GetDataStore("playerStars", player.UserID)?
does that work?
hm
nbm
nvm
still someone answer my question anyhow so that i'm sure
So from a short read you use GetDataStore to fetch the datastores name
You dont add player.UserId
You would save alot of time by either
Using ProfileStore (I recommend)
Or
If you want to make your own first watch a tutorial
If we referee to this
It gets a datastore named Name
Then uses GetAsync with the user player_userid
To fetch their specific data
Today we look at a new library for easily saving player data inside of Roblox! The Profile Store library is created by the same developer of the Profile Service library, which we've used for saving our player data for so long.
Subscribe for more Roblox development tutorials!
Profile Store Dev Forum post:
https://devforum.roblox.com/t/profilesto...
This video was the start of actualling making games for me