Why does this point system give all players points?

Point Giving Script

local DataStoreService  = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local PointsStore = DataStoreService:GetDataStore("PointsStore")
function LoadPlayer(Player)
	local Folder  = Instance.new("Folder")
	Folder.Name = "leaderstats"
	Folder.Parent = Player

	local Points = Instance.new("NumberValue")
	Points.Name  = "Wins"
	Points.Parent = Folder

	local Data = PointsStore:GetAsync(Player.UserId)
	if Data then
		Points.Value = Data
	else Points.Value = 0


		
	end
-------------------------------This part gives the points-------------------
	game.ReplicatedStorage.WinSystem.AddWin.Event:Connect(function()
		for i,Player in ipairs(game.Teams.Player:GetPlayers()) do 
			Points.Value += 1
			warn("ADDED 1 POINT TO "..Player.Name..".  PLAYER NOW HAS "..Points.Value.." POINTS")
		end
		task.wait(1.5)
		game.ReplicatedStorage.WinSystem.WinFinished:Fire()
	end)
-----------------------------------------------------
end

function SavePlayer(Player)
	PointsStore:SetAsync(Player.UserId, Player.leaderstats.Wins.Value)
	warn("Saved "..Player.Name)
end

Players.PlayerAdded:Connect(LoadPlayer)
Players.PlayerRemoving:Connect(SavePlayer)

This is the script where the AddWin comes from

local pl = game:GetService('Players')
local teams = game:GetService('Teams')


-------This part is activated when the round is finished and everything is reset---------
	game.ReplicatedStorage.GUIEvents.WinnerListEvent.Event:Connect(function()
		game.ReplicatedStorage.WinSystem.AddWin:Fire()
		warn("FIRED EVENT")
	end)
	-------------------------------------


game.ReplicatedStorage.GUIEvents.SecondEvent.Event:Connect(function(player)
			for i, plr in pairs(game.Players:GetPlayers()) do
				plr.Team = teams.Player
			end
end)
--------------------Event from the other script activates this--------------
game.ReplicatedStorage.WinSystem.WinFinished.Event:Connect(function()
	wait(2)
	for i, plr in pairs(game.Players:GetPlayers()) do
		plr.Team = teams.Player
	end
	
end)
--------------------------------------------------------------

I have two teams: Player and Spectator. When a round is over, it should give everyone still on the Player team 1 point. But if there’s still one person alive on the Player team, the entire server gets a point. Why does it do this and how do I fix it?

the listener for the AddWin event is part of function LoadPlayer. Every time a player is loaded, the function is now listening for AddWin for all players which is presumably causing your problem.

So should the AddWin function be placed outside of LoadPlayer?

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