#DataStore help

46 messages · Page 1 of 1 (latest)

obsidian bison
#

Why is my DataStore script not working?

local GDS = game:GetService("DataStoreService")
local cash_1 = GDS:GetDataStore("Cash_1")
game.Players.PlayerAdded:Connect(function (player)
    leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    cash = Instance.new("IntValue", leaderstats)
    cash.Name = "Cash" --Change this to the name of what needs to be on the leaderboard
    
    
playerSaveID = "Player_"..player.UserId
    print(playerSaveID.." has joined!")
    local success, errormessage = pcall(function()
end)
        local data = cash_1:GetAsync(playerSaveID)
        if success then
            data = cash.Value
            print(playerSaveID.."'s save restored!")
    end
end)


game.Players.PlayerRemoving:Connect(function()
    local data = cash.Value
    local success, errormessage = pcall(function()
        cash_1:SetAsync(playerSaveID,data)
        end)
        if success then
            print(playerSaveID.."'s data saved!")
        end
    end)```
obsidian bison
obsidian bison
#
local GDS = game:GetService("DataStoreService")
local cash_1 = GDS:GetDataStore("Cash_1")

local playerSaveID

game.Players.PlayerAdded:Connect(function(player)
    leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    cash = Instance.new("IntValue", leaderstats)
    cash.Name = "Cash"
    
    playerSaveID = "Player_"..player.UserId
    print(playerSaveID.." has joined!")
    
    local success, errormessage = pcall(function()
        local data = cash_1:GetAsync(playerSaveID)
        if data ~= nil then
            cash.Value = data
            print(playerSaveID.."'s save restored!")
        end
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    local data = cash.Value
    local success, errormessage = pcall(function()
        cash_1:SetAsync(playerSaveID, data)
    end)
    if success then
        print(playerSaveID.."'s data saved!")
    end
end)```
obsidian bison
#

but that looks bad

#

so im going to make it look better

#

like make it look much better

obsidian bison
#

im going to make it look better for u

obsidian bison
# obsidian bison wow, it works. what did you change? i need to know for the future
local DataStore = game:GetService('DataStoreService'):GetDataStore('TEst')
function OnPlayer(player)
    local ls = Instance.new('Folder',player)
    local cash = Instance.new('NumberValue',ls)
    local saving = DataStore:GetAsync(player.UserId)
    ls.Name = 'leaderstats'
    cash.Name = 'cash'
    if saving then
        cash.Value = saving.cash
    end
end
function OnLeaving(player)
    local ls = player:FindFirstChild('leaderstats')
    local cash = ls:FindFirstChild('cash')
    DataStore:SetAsync(player.UserId,cash.Value)
end
local Player = game.Players
Player.PlayerAdded:Connect(function(player)
    OnPlayer(player)
end)
Player.PlayerRemoving:Connect(function(player)
    OnLeaving(player)
end)```
obsidian bison
#
local plr = game.Players.LocalPlayer
local Status = game.ReplicatedStorage:WaitForChild('cashNum')
local GUI = script.Parent

game.Players.PlayerAdded:Connect(function(localPlayer_)
    local cash = localPlayer_:WaitForChild("leaderstats").Cash
    Status.Value = cash.Value
    cash.Changed:Connect(function()
        GUI.Text = "$" .. Status.Value
    end)
end)```
obsidian bison
obsidian bison
#

because i know what to do

#

aka dev forum

#

and testing

obsidian bison
obsidian bison
stiff shuttle
obsidian bison
#

but its because i have mastered 4 code languages and i know about 14 code languages

stiff shuttle
#

you must have degree then

#

im assuming

obsidian bison
#

na almost failed highschool with a gpa of 2.1

stiff shuttle
#

i think its not about how much language you learn but how you apply it

stiff shuttle
#

what do u do now then

obsidian bison
#

in the 4 mastered i created my own bignum systems and one of them is lua
and its not 1000 to 1k
its 1000 to 1e3

stiff shuttle
#

is it big number?

obsidian bison
#

so what ever u have anything over 1e308 it stops and then converts to inf
aka Infinity

stiff shuttle
#

interesting

#

well

#

im just starting my coding journey

#

Its overwhelming how much math i have to learn

obsidian bison
#

i started lua 6 months ago

stiff shuttle
#

well they are kinda true

obsidian bison
#

nope i learned from the 3 other complex languages
so it took me a while to understand on what the lua does