Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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!

2 comments

0

Oops the scripts are messed up. I hope you can still read it

0

This won't work, fix your script or remove the post. This is unreadable

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.