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

Can someone help me with making a script that increases the cash a player has?

Asked by 5 years ago
Edited 5 years ago

this is my scripts so far..

.~~~~~~~~~~~~~~~~~ local Cash = game.Players. --what goes here again? local CashPart = script.Parent local count = game.Workspace.Counter local function onPartTouch (otherPart) if (count)then Cash = Cash + 10 end

end


and then there is this script...
local currencyName = "Cash"

local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")

game.Players.PlayerAdded:Connect(function(player) local folder = Instance.new("Folder") folder.Name= "leaderstats" folder.Parent = player

local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder

local ID = currencyName.."-".. player.UserId
local savedData = nil

pcall (function()
    savedData = DataStore: GetAsysc(ID)
end)

end) ~~~~~~~~~~~~~~~~~

i'm trying to make the Currency go up by 10 when the Clone Part touches the Counter. Please Help Me!

0
Oops the scripts are messed up. I hope you can still read it archerdancom -3 — 5y
0
This won't work, fix your script or remove the post. This is unreadable karlo_tr10 1233 — 5y

1 answer

Log in to vote
0
Answered by
3wdo 198
5 years ago
Edited 5 years ago

i see your putting datastore in for data store:

local DSService = game:GetService('DataStoreService'):GetDataStore('data')
game.Players.PlayerAdded:connect(function(plr)
    -- Define variables
    local uniquekey = 'id-'..plr.userId
    local leaderstats = Instance.new('IntValue', plr)
    local savevalue =  Instance.new('IntValue')
    leaderstats.Name = 'leaderstats'
    savevalue.Parent = leaderstats
    savevalue.Name = 'Cash'

    -- GetAsync
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        savevalue.Value = GetSaved[1]
    else
        local NumbersForSaving = {savevalue.Value}
        DSService:SetAsync(uniquekey, NumbersForSaving)
    end
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Cash.Value}
DSService:SetAsync(uniquekey, Savetable)    


end)

for cash increase:

amount = 2 -- This variable is the amount of cash we will give each time.
timedelay = 2 -- This variable is the amount of seconds inbetween each time the cash is rewarded
currencyname = "Cash" -- This is the name of your Currency

while true do
    wait(timedelay)
    for i,v in pairs(game.Players:GetPlayers()) do
        if v:FindFirstChild("leaderstats") and v then
            v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
        end
    end

end

Ad

Answer this question