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

1and then there is this script...
1local 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

01local currency = Instance.new("IntValue")
02currency.Name = currencyName
03currency.Parent = folder
04 
05local ID = currencyName.."-".. player.UserId
06local savedData = nil
07 
08pcall (function()
09    savedData = DataStore: GetAsysc(ID)
10end)

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:

01local DSService = game:GetService('DataStoreService'):GetDataStore('data')
02game.Players.PlayerAdded:connect(function(plr)
03    -- Define variables
04    local uniquekey = 'id-'..plr.userId
05    local leaderstats = Instance.new('IntValue', plr)
06    local savevalue =  Instance.new('IntValue')
07    leaderstats.Name = 'leaderstats'
08    savevalue.Parent = leaderstats
09    savevalue.Name = 'Cash'
10 
11    -- GetAsync
12    local GetSaved = DSService:GetAsync(uniquekey)
13    if GetSaved then
14        savevalue.Value = GetSaved[1]
15    else
View all 27 lines...
01for cash increase:
02 
03amount = 2 -- This variable is the amount of cash we will give each time.
04timedelay = 2 -- This variable is the amount of seconds inbetween each time the cash is rewarded
05currencyname = "Cash" -- This is the name of your Currency
06 
07while true do
08    wait(timedelay)
09    for i,v in pairs(game.Players:GetPlayers()) do
10        if v:FindFirstChild("leaderstats") and v then
11            v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
12        end
13    end

end

Ad

Answer this question