Problem with Datastore

Hi, I have a question about this script, I watched this from a tutorial somewhere but it doesn’t work. What is wrong with this and what can I change? Thank you in advance! This is my code:

local DSS = game:GetService("DataStoreService")

local MyData = DSS:GetDataStore("MyDataStore")

game.Players.PlayerAdded:Connect(function(plr)
    local LS = Instance.new("Folder")
    LS.Name = "leaderstats"
    LS.Parent = plr
    
    local Money = Instance.new("IntValue")
    Money.Name = "Money"
    Money.Parent = LS
    local data 
    local success, errormessage = pcall(function()
        data = MyData:GetAsync(plr.UserId.."-money")

    end)
    if success then 
        Money.Value = data
    else 
        print("There is a error")
        warn(errormessage)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local success, errormessage = pcall(function()
        MyData:GetAsync(plr.UserId.."-money", plr.leaderstats.Money.Value)

    end)
    if success then 
        print("The data will be stored for "..plr.Name)
    else 
        print("Something went wrong while saving ".. plr.Name.. "'s data")
        warn(errormessage)
    end
end)
1 Like

Can you show the error in output?

I have no error :face_with_raised_eyebrow: I give myself money through a party and then I rejoin and then it’s 0 again

Testing through Roblox studio won’t save your data

1 Like

I know, it was also in the normal game with no edit. API / HTTP services are also already on

1 Like

Have you published your edits to the game?

1 Like

Yes I have already done that I also just have the leaderstats in my screen. Only when I rejoin everything is 0 again while it was 500 before

1 Like

maybe the problem in the coin which give you money it maybe work at cilent side and data store save server sie only can i see the script?

1 Like

Yeah sure.

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
   plr.leaderstats.Money.Value = plr.leaderstats.Money.Value +100
end)
1 Like

image

1 Like

I have founded the problem, this problem is solved.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.