Leaderboard Problem

Good Morning, I have a problem where when one person gets a stat everyone gets it. Pls help

This is a server script in ServerScriptService

local RS = game.ReplicatedStorage

game.Players.PlayerAdded:Connect(function(player)

	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = player
	leaderstats.Name = "leaderstats"

	local Gamepasses = Instance.new("Folder")
	Gamepasses.Parent = player
	Gamepasses.Name = "Gamepasses"

	local Money = Instance.new("IntValue")
	Money.Name = "Money"
	Money.Parent = leaderstats

	local Rolls = Instance.new("IntValue")
	Rolls.Name = "Rolls"
	Rolls.Parent = leaderstats

	local QuickRoll = Instance.new("IntValue")
	QuickRoll.Name = "QuickRoll"
	QuickRoll.Parent = Gamepasses

	local AuraStorage = Instance.new("Folder")
	AuraStorage.Parent = player
	AuraStorage.Name = "AuraStorage"

	local GeneralStats = Instance.new("Folder")
	GeneralStats.Parent = player
	GeneralStats.Name = "GeneralStats"

	local Settings = Instance.new("Folder")
	Settings.Parent = player
	Settings.Name = "Settings"

	local InventoryLimit = Instance.new("IntValue")
	InventoryLimit.Name = "InventoryLimit"
	InventoryLimit.Parent = GeneralStats
	InventoryLimit.Value = 8

	local InventoryFull = Instance.new("BoolValue")
	InventoryFull.Name = "InventoryFull"
	InventoryFull.Parent = GeneralStats

	local EquippedAura = Instance.new("StringValue")
	EquippedAura.Name = "EquippedAura"
	EquippedAura.Value = "None"
	EquippedAura.Parent = GeneralStats

	local AutoEquip = Instance.new("StringValue")
	AutoEquip.Name = "AutoEquip"
	AutoEquip.Parent = Settings

	local AutoSkip = Instance.new("StringValue")
	AutoSkip.Name = "AutoSkip"
	AutoSkip.Parent = Settings

	local MusicVolume = Instance.new("StringValue")
	MusicVolume.Name = "MusicVol"
	MusicVolume.Parent = Settings
	
	for i,v in pairs(game.ReplicatedStorage.TitleResources:GetChildren()) do
		local Aura = Instance.new("IntValue")
		Aura.Name = v.Name
		Aura.Parent = AuraStorage
	end
	
	
	local function GiveMoney()

		Money.Value += 1
	end

	local function IncreaseLimit()

		InventoryLimit.Value += 1
	end

	local function GiveAura(aura, amount)

	AuraStorage:WaitForChild(aura).Value += amount
		
	end

	local function GiveRolls()

		Rolls.Value += 1
	end

	local function BuyQuickRoll()

		QuickRoll.Value += 1
	end

	local function ChangeEquippedAura(aura)

		EquippedAura.Value = aura

	end

	local function ApplySettings(Equip, Skip, MusicVol)

		AutoEquip.Value = Equip
		AutoSkip.Value = Skip
		MusicVolume.Value = MusicVol

	end
	
	
	RS.RemotesFolder.IncreaseRoll.OnServerEvent:Connect(function()
		GiveRolls()
	end)


	local function BuyQuickRollEvent()
		BuyQuickRoll()
	end

	RS.RemotesFolder.IncreaseMoney.OnServerEvent:Connect(function(Player,amount)
		GiveMoney()

	end)

	RS.RemotesFolder.IncreaseLimit.OnServerEvent:Connect(function(player)

		IncreaseLimit()
	end)


	RS.RemotesFolder.SaveAura.OnServerEvent:Connect(function(player,aura)
		aura = aura[1]
		GiveAura(aura, 1)
	end)

	RS.RemotesFolder.ActionEvent.OnServerEvent:Connect(function(Player, Action, aura)
		--warn(Action)
		if Action == "Equip" then
			ChangeEquippedAura(aura)
		end
	end)

	--[[RS.RemotesFolder.CommandGiveAuraStats.Event:Connect(function(player,aura)
		for i,v in pairs(profile.Data.Auras) do
			if i == aura then
				GiveAura(profile,aura,1)
			end
		end
	end)--]]

	RS.RemotesFolder.ApplySettings.OnServerEvent:Connect(function(player, Equip, Skip, MusicVol)
		ApplySettings(Equip, Skip, MusicVol)
	end)

	RS.RemotesFolder.DestroyRarity.OnServerEvent:Connect(function(player,aura)
				GiveAura(aura,-1)
				ChangeEquippedAura("None")
	end)


	RS.RemotesFolder.BuyQuickRoll.OnServerEvent:Connect(BuyQuickRollEvent)
end)

You’re having this problem because those script connections are being opened for every player when they join. You should instead only create the folders and attributes within your PlayerAdded event function. When you call a function to add money, you should pass the player to add it to so that it will add it to the appropriate player instead of those events being received once for every player in the game.

So i put the Give() functions outsize the playerAdded function?

Yes. Placing your functions outside of the PlayerAdded function and then passing the appropriate player into them from the event should solve your problem.

how should i access the player then?

RemoteEvent.OnServerEvent will pass the player that fired the event as its first argument. Here’s an example.

RemoteEvent.OnServerEvent:Connect(function(Player)
-- where Player is the Player instance of the player that fired the event, so things like Player:Kick() will work here
end)

Then you can pass the Player object into the function to add it to the appropriate player.

Here’s the RemoteEvent Documentation if you want more information on how they work.

Thank You! It works now

See you later

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.