#datastoreservice script not working

1 messages · Page 1 of 1 (latest)

topaz sapphire
#

i'm using a server script and i'm trying to get userid for dataservices but it's not working i'm using player.userid btw

real zinc
#

not working how so?

topaz sapphire
#

it's just like

#

it keeps saying error-type when i hover over it

#

like it's not detecting it

#

as an actual statement

real zinc
topaz sapphire
#

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)
real zinc
topaz sapphire
#

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

real zinc
topaz sapphire
#

yeah it's not finished yet

#

i'm working on it

real zinc
topaz sapphire
#

yeah i'm alr dw i can figure this out

humble jacinth
#

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

topaz sapphire
#

oh shi

#

wait lemme do it in abit

topaz sapphire
#

wait no it's not

fickle daggerBOT
#

studio** You are now Level 4! **studio

topaz sapphire
#

wait idk wait one sec

#

nahh says stars isn't a valid ,member of player ivnneoyty

#

inventory

humble jacinth
#

well idk how youve set up that

#

but i think you can only put one arguement

topaz sapphire
#

damnnn

#

maybe i wrote it wrong idk

humble jacinth
#

Try getting only the player inventory

#

Then print it

#

See what's inside

#

If Stars is inside you can access stars from it

topaz sapphire
#

alright

#

1 sec

#

i finished writing the scripts but i'm having problems

topaz sapphire
#

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

humble jacinth
#

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

topaz sapphire
#

Shit

#

OK thx dude I'll try this when I get back onto my pc

topaz sapphire
#

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

humble jacinth
#

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

topaz sapphire
#

oooooooh

#

yeah i've heard of profilestore

#

i bettetr check it out then heh thx

humble jacinth
#

This video was the start of actualling making games for me

topaz sapphire
#

AH MAN

#

thx for the vid omg

#

u didn't have too lel but thx alot heh this is rlly gonna help me, thx for all of ur help man :D