When i join the game for the first time it doesn’t give the cash and it says that i have a multiplier but when i rejoin it gives the cash. I don’t understand the problem!
local Short = require(game.ReplicatedStorage.Short)
local datastoreservice = game:GetService("DataStoreService")
local mydatastore = datastoreservice:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Level = Instance.new("NumberValue")
Level.Name = "Level"
Level.Value = 0
Level.Parent = leaderstats
local currencies = Instance.new("Folder")
currencies.Name = "currencies"
currencies.Parent = player
local Money = Instance.new("NumberValue")
Money.Name = "Money"
Money.Value = 0
Money.Parent = currencies
local Multiplier = Instance.new("NumberValue")
Multiplier.Name = "Multiplier"
Multiplier.Value = 1
Multiplier.Parent = currencies
local Rebirth = Instance.new("NumberValue")
Rebirth.Name = "Rebirth"
Rebirth.Value = 0
Rebirth.Parent = currencies
local UltraRebirth = Instance.new("NumberValue")
UltraRebirth.Name = "UltraRebirth"
UltraRebirth.Value = 0
UltraRebirth.Parent = currencies
local Prestige = Instance.new("NumberValue")
Prestige.Name = "Prestige"
Prestige.Value = 0
Prestige.Parent = currencies
local MegaRebirth = Instance.new("NumberValue")
MegaRebirth.Name = "MegaRebirth"
MegaRebirth.Value = 0
MegaRebirth.Parent = currencies
local GigaRebirth = Instance.new("NumberValue")
GigaRebirth.Name = "GigaRebirth"
GigaRebirth.Value = 0
GigaRebirth.Parent = currencies
local UltraPrestige = Instance.new("NumberValue")
UltraPrestige.Name = "UltraPrestige"
UltraPrestige.Value = 0
UltraPrestige.Parent = currencies
local playerUserId = "Player_"..player.UserId
-- loads DATA
local data
local success, errormessage = pcall(function()
data = mydatastore:GetAsync(playerUserId)
end)
if success then
Money.Value = data.Money
Multiplier.Value = data.Multiplier
Rebirth.Value = data.Rebirth
UltraRebirth.Value = data.UltraRebirth
Prestige.Value = data.Prestige
MegaRebirth.Value = data.MegaRebirth
GigaRebirth.Value = data.GigaRebirth
UltraPrestige.Value = data.UltraPrestige
Level.Value = data.Level
end
while wait(0.1) do
Money.Value = Money.Value + (1*Multiplier.Value) -- add *reb.Value and *ult.Value and *pre.Value if u want rebirths and ultra rebirths and prestiges to multiply cash earnings
Level.Value = ((math.log10(Money.Value+1)*0.001)+((math.log10(Multiplier.Value)*0.01))+((math.log10(Rebirth.Value+1)*0.1))+((math.log10(UltraRebirth.Value+1)*1))+((math.log10(Prestige.Value+1)*10))+((math.log10(MegaRebirth.Value+1)*100))+((math.log10(GigaRebirth.Value+1)*1000))+((math.log10(UltraPrestige.Value+1)*10000)))
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = {
Money = player.currencies.Money.Value;
Multiplier = player.currencies.Multiplier.Value;
Rebirth = player.currencies.Rebirth.Value;
UltraRebirth = player.currencies.UltraRebirth.Value;
Prestige = player.currencies.Prestige.Value;
MegaRebirth = player.currencies.MegaRebirth.Value;
GigaRebirth = player.currencies.GigaRebirth.Value;
UltraPrestige = player.currencies.UltraPrestige.Value;
Level = player.leaderstats.Level.Value
}
local success, errormessage = pcall(function()
mydatastore:SetAsync(playerUserId, data)
end)
if success then
print("Data succesfully saved!")
else
print("There was an error!")
warn(errormessage)
end
end)