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

How do I allow players to save their in game purchases they buy with the in game currency?

Asked by 6 years ago
Edited 6 years ago

How do I allow players to save their in game purchases they buy with the in game currency.

My Code for purchasing an item with in game currency (cash)

local plr = game.Players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")

script.Parent.MouseButton1Click:connect(function()
    if plr.Backpack:FindFirstChild("GravityCoil") or plr.StarterGear:FindFirstChild("GravityCoil") or game.Workspace[plr.Name]:FindFirstChild("GravityCoil") then
        script.Parent.Parent.TextLabel.Text = "You have already bought this item!"
        wait(3)
        script.Parent.Parent.TextLabel.Text = "SHOP"
        else

    if plr.leaderstats.Cash.Value >= 500000 then
        replicatedstorage.GravityCoil:Clone().Parent = plr.Backpack
        replicatedstorage.GravityCoil:Clone().Parent = plr.StarterGear
    else
    local cashrequired = 500000 - plr.leaderstats.Cash.Value
    script.Parent.Parent.TextLabel.Text = "You need "..cashrequired.." more money to buy this item"
    wait(3)
    script.Parent.Parent.TextLabel.Text = "SHOP"
    end

    end



end)


I made this code to save the cash a player has in my game and it works. How would I use it to also save the in game purchases of a player.

My Purchasable Items are in replicatedstorage.

How would I make sure that the player can keep their purchase so they when they rejoin the game they still have the gear they purchased with in game currency.

CashStore = game:GetService("DataStoreService"):GetDataStore("DataStore")

function PlayerEntered(player)
    repeat wait() until player.Character

    local stats = Instance.new("IntValue")
    stats.Parent = player
    stats.Name = "leaderstats"

    local cash = Instance.new("IntValue")
    cash.Parent = stats
    cash.Name = "Cash"

    if CashStore:GetAsync("Points_"..player.Name) ~= nil then
        cash.Value = CashStore:GetAsync("Points_"..player.Name)
    else
        cash.Value = 0
    end

    cash.Changed:connect(function(Val)
        CashStore:SetAsync("Points_"..player.Name, Val)
    end)
end

game.Players.PlayerAdded:connect(PlayerEntered)

Thank You and help is appreciated

0
i looked at that but i still didnt understand aspiringstar346 8 — 6y
0
it doesnt say how to save purchases aspiringstar346 8 — 6y
1
It isn't going to tell you exactly what to do, it gives you the information you need to "build" the script you would use. Read it through a little more "carefully" and think about how you could use it to save a player's purchases. EnderGamer358 79 — 6y
View all comments (3 more)
0
Hint: Tables! MooMooThalahlah 421 — 6y
0
um aspiringstar346 8 — 6y
0
i found a helpful video which answered my question ill post link. aspiringstar346 8 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

https://www.youtube.com/watch?v=PZp9nfuqPpQ

Ad

Answer this question