Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Data Store Error [plz help?]

Asked by 3 years ago
Edited 3 years ago

HELP its been about a month my game is delayed cuz the datastore error

Can somebody fix my code to work, im trying to make a DataStore for Cash

link to repost: https://scriptinghelpers.org/questions/107002/data-store-error-plz-help-repost

Output: DS isn't a vaild part of DataModel

Thanks to anybody who fixes it!

local DS = game:GetService("DataStoreService")
local CurrencySave = game.DS:GetService("FirstStore")


game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local cash = Instance.new("IntValue", leaderstats)
    cash.Name = "Fruit"
    cash.Value = 100

    local data
    local success, errormessage = pcall(function(player)
        data:GetAsync(player.UserId.."-cash")
    end)

    if success then
        cash.Value = data
    else
        print("There was an error while getting your data")
        warn(errormessage)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)

    local success, errormessage = pcall (function()
    CurrencySave:SetAsync(player.UserId.."-cash", player.leaderstats.Fruit.Value)
    end)

    if success then
        print("Player data Saved!")
    else
        print("Player Data didn't Save.")
        warn(errormessage)
    end

end)

2 answers

Log in to vote
0
Answered by
DesertusX 435 Moderation Voter
3 years ago
Edited 3 years ago

You are trying to find a child in game called DS and there is no such thing. You already defined the variable so, you don't need to get the Parent again.


Change line 2 to:

local CurrencySave = DS:GetService("FirstStore")

WAIT!!

We're not done. Another error on line 2 is that you are saying :GetService(). This can only be done on game. You are trying to get a service in a service. It just doesn't make sense.

It should be:

local CurrencySave = game.DS:GetDataStore("FirstStore")

We're still not done.

You just added the IntValue Cash in the leaderstatsbut, on line 31, you said:

player.leaderstats.Fruit.Value

I think what you meant was:

player.leaderstats.Cash.Value

If it wasn't what you were trying to do, then please let me know.


Okay, that's it, sir!

I hope this works and make sure to accept this answer if it does!

If it doesn't, then please tell me what errors you are getting in the output.

0
Yes, make sure to put it in "ServerScriptService too". merthjm -8 — 3y
0
DesertusX, Heres the error in the output "DS is not a vaild member of DataModel." BrishedBoomer 29 — 3y
0
Sorry! It should work now! DesertusX 435 — 3y
0
you DestusX lemme hit you up on roblox and add you to team Create BrishedBoomer 29 — 3y
View all comments (3 more)
0
im jack90078 BrishedBoomer 29 — 3y
0
Sure! DesertusX 435 — 3y
0
add me back BrishedBoomer 29 — 3y
Ad
Log in to vote
-1
Answered by
iuclds 720 Moderation Voter
3 years ago

This code is destined to work.

local DS = game:GetService("DataStoreService")
local CurrencySave = DS:GetDataStore("FirstStore")


game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local cash = Instance.new("IntValue", leaderstats)
    cash.Name = "Fruit"
    cash.Value = 100

    local data
    local success, errormessage = pcall(function(player)
           data:GetAsync(player.UserId.."-cash")
    end)

    if success then
        cash.Value = data
    else
        print("There was an error while getting your data")
        warn(errormessage)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)

    local success, errormessage = pcall (function()
    CurrencySave:SetAsync(player.UserId.."-cash", player.leaderstats.Fruit.Value)
    end)

    if success then
        print("Player data Saved!")
    else
        print("Player Data didn't Save.")
        warn(errormessage)
    end

end)

Answer this question