I have to Variables, Cash and Experience. I need to keep these variables the same because I'm already using them in other scripts. I need to save these two values to the server and open them up on game entrance. The problem in my following script is make everyone in the game share the same leader stats and progress. Please Help Me.
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
local cashStore = DataStoreService:GetDataStore("PlayerCash")
game.Players.PlayerAdded:Connect(function(plr)
print(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local cash = Instance.new("IntValue")
cash.Name = "Cash"
if cashStore:GetAsync(plr)==nil or cashStore:GetAsync(plr)==0 then
cash.Value = 12000
else
cash.Value = cashStore:GetAsync(plr)
end
cash.Parent = leaderstats
local experience = Instance.new("IntValue")
experience.Name = "Experience"
if experienceStore:GetAsync(plr)==nil or experienceStore:GetAsync(plr)==0 then
experience.Value = 0
else
experience.Value = experienceStore:GetAsync(plr)
end
experience.Parent = leaderstats
wait(10)
repeat
cash.Value = cash.Value + 820
cashStore:SetAsync(plr, cash.Value)
wait(10)
experience.Value = experience.Value +45
experienceStore:SetAsync(plr, experience.Value)
until
true == false
end)

3 comments
He did that; read the script before reasoning.
He's using only plr, the right way would be plr.UserId.
His Solution worked perfectly, thanks so much zamd157!