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

I am completely at a loss, how do I make a currency system?

Asked by 3 years ago
Edited 3 years ago

I am new to roblox studio and Lua in general. I have been trying to make a currency system for days but I cannot figure it out. I believe my ServerStorage script works properly but the amount of money shown on the in game GUI does not save and always restarts back at 0.

local DataStoreService = game:GetService('DataStoreService')
local PlayerData = DataStoreService:GetDataStore('PlayerData')

local function onPlayerJoin(player)
  local leaderstats = Instance.new('Folder')
        leaderstats.Name = 'leaderstats'
    leaderstats.Parent = player
    print('player joined')

    local Dollas = Instance.new('IntValue')
    Dollas.Name = 'Dollas'
    Dollas.Parent = leaderstats

    local playerUserId = 'Player Id: '..player.UserId
    local data = PlayerData:GetAsync(playerUserId)

    if data then
        Dollas.Value = data
    else
        Dollas.Value = 0
    end
end

local function onPlayerLeave(player)
    local success, err = pcall(function()
        local playerUserId = 'Player Id: '..player.UserId
        PlayerData:SetAsync(playerUserId, player.leaderstats.Dollas.Value)
        print('player left')
    end)
    if not success then
        print('player not saved')
        warn('Could not save data')
    end
end

game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerLeave)
0
Are you testing in roblox studio? OhBrotherGaminYT 11 — 3y
0
I tried in studio with API enabled. Another issue I've been having is that my game just will not publish when I click publish. I made it Public as well but I still can't even see it there DaGlizzzzzzyyyy 34 — 3y
1
Press alt p to publish your game, also use BindToClose as well to save the data. greatneil80 2647 — 3y
0
thank ya sir it work. I'd upvote but my reputation is too low whatever that means DaGlizzzzzzyyyy 34 — 3y

Answer this question