I want that only the winner recieve points, not all the players

  1. What do i want to achieve? I want that if a player win then he recieve points

  2. What is the issue? The problem is that all people in the server recieve points and not only the winner(i fireserver bc if i add points in a localscript the datasave doesn’t work )

so basically there are 3 script, 1 for check the winners, another for do labels with the winner name, winner image … ecc and another for give points

This is the one that check the winners

local part = script.Parent
local winners = {}
local rep = game:GetService("ReplicatedStorage")
local cooldown = false

part.Touched:Connect(function(hit)
	
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if plr then

		if #winners == 0 then
			print("touched winner")
			table.insert(winners,plr)
			rep.Won:FireAllClients(winners)
		end
		
		for i, v in pairs(winners) do
			
			if plr == v then
				break
			end
			
			if i == #winners then
				print("touched winner")
				table.insert(winners,plr)
				rep.Won:FireAllClients(winners)
				

			end
			
		end
	end
	
	--the the winners text labels will dissappear in 7 seconds after the first person wins
	
	if cooldown == false then
		cooldown = true
		wait(160)
		
		
		
		winners = {}
		--rep.Finished:FireAllClients()
		cooldown = false
		
	end
end)

This is for do labels with the name of the winner ecc

local rep = game:GetService("ReplicatedStorage")
local won = rep:WaitForChild("Won")
local fin = rep:WaitForChild("Finished")
local label = rep.Winners

won.OnClientEvent:Connect(function(winners)
	
	print("fired")
	local labelClone = label:Clone()
	local smalllabelclone = game.ReplicatedStorage.SmallWinner:Clone()
	
	local plr = winners[#winners]
	local userId = plr.UserId
	
	smalllabelclone.name.Text = plr.Name
	smalllabelclone.avatar.Image = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
	labelClone.name.Text = plr.Name
	labelClone.avatar.Image = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

	
	if #winners == 1 then	
		labelClone.Parent = script.Parent
		labelClone.BackgroundColor3 = Color3.new(1, 0.815686, 0.258824)
		labelClone.rank.Text = "#1"
		game.ReplicatedStorage.Particleswin:FireServer()
		labelClone:TweenPosition(UDim2.new(0.124, 0,0.156, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Elastic, 0.5, false)
		local first = winners[1]
		print(first)
		rep.winner1st:FireServer(first)
--In thye line above i fireserver for add points
	elseif #winners == 2 then
		labelClone.Parent = script.Parent
		labelClone.BackgroundColor3 = Color3.new(0.827451, 0.933333, 1)
		labelClone.rank.Text = "#2"
		labelClone:TweenPosition(UDim2.new(0.124, 0,0.292, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Elastic, 0.5, false)
		print(winners[2])
		
	elseif #winners == 3 then
		labelClone.Parent = script.Parent
		labelClone.BackgroundColor3 = Color3.new(0.729412, 0.458824, 0.266667)	
		labelClone.rank.Text = "#3"
		labelClone:TweenPosition(UDim2.new(0.124, 0,0.426, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Elastic, 0.5, false)

	end
end)

and it is the script that gives points (i did a lot of thing for be sure that only the winner recieve points, but it didn’t work anymore)

game.ReplicatedStorage.winner1st.OnServerEvent:Connect(function(first)
	local name = first.Name
	local char = game.Workspace:FindFirstChild(name)
	if first and char then
		if game.Players:GetPlayerFromCharacter(char) then
			first.leaderstats.Points.Value = first.leaderstats.Points.Value + 5
		end
end	
end)

All answer are welcome : D

Correct me if I’m wrong, but I think the problem is that you’re using the FireAllClients function instead of FireClient.

Also in the OnServerEvent the first parameter will always be the player, so first will be the player. You’ll have to add the player as the 1st parameter and then first as the 2nd parameter.

1 Like

Ty for the answer, i try it rn

Edit: Tysm it works : D