So I have a question, what is wrong with my code here -
Problem : I want to have two leaderstats Minutes and Cash
Minutes : Show on leaderboard
Cash : Is just stored in the player not on leaderboard
I already have the main script for saving and Minutes, ATM This is working :
@author TwinPlayzDev_YT
@since 1/28/2021
This script will save and put minutes on the leaderboard. You can change minutes to anything--
you would like just simply read the code and look at Minutes.Name = "Minutes" change "Minutes"
to anything like "Points", "Level", etc. Please watch my youtube tutorial if needed.
--]]
--[ SERVICES ]--
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TimeStats")
local service = game:GetService("MarketplaceService")
--[ LOCALS ]--
local VIPGamepassId = 13913938 -- VIP GAMEPASS ID
local GamepassId = 13914120 -- GAMEPASS ID
--[ FUNCTIONS ]--
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Minutes = Instance.new("IntValue")
Minutes.Name = "Minutes" -- changing name here (points, levels, time, etc.)
Minutes.Value = 0 -- default value
Minutes.Parent = Leaderstats
local Cash = Instance.new("IntValue")
Cash.Name = "Cash" -- changing name here (points, levels, time, etc.)
Cash.Value = 0 -- default value
Cash.Parent = Player
local Data = DataStore:GetAsync(Player.UserId)
if Data then
Minutes.Value = Data
Cash.Value = Data
end
local incrementValue = 1 -- value when adding points
if (service:UserOwnsGamePassAsync(Player.UserId, VIPGamepassId)) then -- 3x gamepass
incrementValue = 3
elseif (service:UserOwnsGamePassAsync(Player.UserId, GamepassId)) then -- 2x gamepass
incrementValue = 2
end
coroutine.resume(coroutine.create(function() -- gives 1 point every minute
while true do
wait(60)
Minutes.Value = Minutes.Value + incrementValue -- adds points based off of the incrementValue
Cash.Value = Cash.Value + incrementValue
end
end))
end)
game.Players.PlayerRemoving:Connect(function(Player) -- save function here
DataStore:SetAsync(Player.UserId, Player.leaderstats.Minutes.Value)
DataStore:SetAsync(Player.UserId, Player.Cash.Value)
end)
The only problem is that my leaderstat’s “Cash” is combining with “Minutes” I’m guessing because I’m storing it in the same place?
Like my Cash is The Amount Of Minutes.
Im trying to achieve a Cash Money Gui Like Such -
But The 0 is turning into - The Minutes Leaderstat.
Let me know what’s wrong in my script.