Leaderstats updates for only one player

Hello! I had somebody join me in my simulator and once they joined. Everytime I click on a point button, they get the point instead of me. Vice versa, if they join me, I get the point instead of them! Please help me!

local DS = game:GetService("DataStoreService")
local RS = game:GetService("ReplicatedStorage")
local ColorData = DS:GetDataStore("Colors")


local GetColor = false
local colorevent = RS.Color

local player = game.Players


player.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = 'leaderstats'
	leaderstats.Parent = plr
	
	local ColorPoints = Instance.new("IntValue")
	ColorPoints.Name = "🎨 Color"
	ColorPoints.Value = 0
	ColorPoints.Parent = leaderstats
	-- [Rarity] --
	colorevent.OnServerEvent:Connect(function(play, Points)
		if GetColor == false then
			GetColor = true
			play.leaderstats["🎨 Color"].Value += Points
			task.wait(1)
			GetColor = false
			
		end
	end)

	--------
	local Data
	local success, errormsg = pcall(function()
		Data = ColorData:GetAsync(plr.UserId.."- Color")
	
	end)
	if success then
		print("Loaded")
		
		plr.leaderstats["🎨 Color"].Value = Data
	else
		warn(errormsg)
		
	end
	
	
end)

player.PlayerRemoving:Connect(function(plr)
	local Succes, errormessage = pcall(function()
		ColorData:SetAsync(plr.UserId.."- Color", plr.leaderstats["🎨 Color"].Value)
	end)

	if Succes then	
		print('Success!')

	else
		print("Error, data not saved!")
		warn(errormessage)


	end
	
end)

game:BindToClose(function(p)
	for _, playr in pairs(game.Players:GetPlayers()) do
		local ID = "Player_"..playr.UserId
	
		local success, errormsg = pcall(function()
			ColorData:SetAsync(ID, p.leaderstats["🎨 Color"].Value)
			print("Yay, Saved!")
		end)
	
	end
	
end)
1 Like

Change:

play.leaderstats["🎨 Color"].Value += Points

To:

plr.leaderstats["🎨 Color"].Value += Points
4 Likes

I did but it still updates the value to the other player who joins. I’m just confused on why it’s doing that when it’s not supposed to

You should not be sending points from the client, unless you want the client to be able to determine what points is.

It’s on a module script so that shouldn’t be considered a client, right?

If the module script is called from the client said call is client-sided. The same goes for server, if you run a module function from the server its server sided.

1 Like

Ah I see, I’m using the client-side. Should I transform the game into server Side?

Any reason on why this is on inside a playeradded connection?

I changed the script to a different one. I switched out “play” to plr which is the player added function. So that’s why it’s inside.