game.Players.PlayerAdded:connect(function(player)

local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
 
 local cash = Instance.new("IntValue")
 cash.Name = "Cash" ----- Name of currency
 cash.Value = 0
 cash.Parent = folder
 
 player.CharacterAdded:Connect(function(character)
  character.Humanoid.Died:Connect(function()
   local tag = character.Humanoid:FindFirstChild("creator")
   if tag ~= nil then
    local player = tag.Value
    local bounty = 20
    
    local leaderstats = player:WaitForChild("leaderstats")
    leaderstats.Cash.Value = leaderstats.Cash.Value + bounty
       end
     end)
  end)
end)

local ID = currencyName.."-"..player.UserId
	local savedData = nil	
	
	pcall(function()
		savedData = DataStore:GetAsync(ID)
	end)
	
	if savedData ~= nil then
		currency.Value = savedData
		print("Data loaded")
	else
		-- New player
		 currency.Value = 50
		 print("New player to the game")
	 end
end) -And here it tells me "Expected eof, got end" What should I do?

game.Players.PlayerRemoving:Connect(function(player)
	local ID = currencyName.."-"..player.UserId
	DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)

game:BindToClose(function()
	
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			player:Kick("This game is shutting down")
		end
	end
	
	wait(5)	
	
end)

1 comment

0

Can you put the entire thing in a code block so it is easier to understand?