Removing Values when a Player Leaves?

I have a game where you can vote for a player and it will give you their name as a Stringvalue in leaderstats. I need it to change that value to None when the player they voted for leaves. I have a script but it does not work at all.

game.Players.PlayerRemoving:Connect(function(plr)
	local Players = game:GetService("Players") 
	local function getPlayersArray()

		local players = {} 
		for _, p in pairs(Players:GetPlayers()) do 
			local points = p:FindFirstChild("leaderstats") 
			print(points)
			table.insert(players, {player = p, Points = points})
			print(points)
		end

		return players 
	end
	getPlayersArray()
end)
2 Likes

Your script has nothing to do with setting the player’s vote to nil??

game.Players.PlayerRemoving:Connect(function(player)
	for i, v in pairs(game.Players:GetPlayers()) do
		local vote = v.leaderstats:WaitForChild("Vote") -- The string value in players' leaderstats. Replace with whatever the name of the string value is
		if vote.Value == player.Name then
			vote.Value = "None"
		end
	end
end)
4 Likes

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