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

Everyone is sharing the same Leader stat?

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)

1 answer

✓ Accepted answer

You should make a variable to maintain as a key using their UserId.

local yourkey = plr.UserId

After that, replace the plr with yourkey variable in :GetAsync and :SetAsync lines.

3 comments

0

He did that; read the script before reasoning.

0

He's using only plr, the right way would be plr.UserId.

0

His Solution worked perfectly, thanks so much zamd157!

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