How do I check if the name of a player from a team matches the value of an objectvalue?

I want to get a player from a team and see if the name of that player is the exact same as the value of an objectvalue but it does not seem to work. Sorry if my code seems sloppy will try and fix it later.

local collector = script.Parent

collector.Touched:Connect(function(hit)
	local findgold = hit:FindFirstChildOfClass("IntValue")
	if findgold then
		local OwnerName = game.Workspace.Tycoon1.OwnerValue.Value
		local Owner = game.Teams.France:GetPlayers()
		if Owner.Name == OwnerName then
			local leaderstats = Owner:FindFirstChild("leaderstats")
			if leaderstats then
				local gold = leaderstats:FindFirstChild("Gold")
				gold.Value += findgold.Value
			end
		end
	end
end)

No errors nor are there any yields.

local teams = game:GetService("Teams")
local team = teams.Team

local objectValue = workspace.ObjectValue --Example reference.

for _, teamPlayer in ipairs(team:GetPlayers()) do
	if objectValue.Value == teamPlayer then
		--Do code.
	end
end
1 Like

This returns an array of players, not a singular,

new

        local Owner = game.Workspace.Tycoon1.OwnerValue.Value
		local OwnerTeam = game.Teams.France
		if Owner.Team == OwnerTeam then
			local leaderstats = Owner:FindFirstChild("leaderstats")
			if leaderstats then
				local gold = leaderstats:FindFirstChild("Gold")
				gold.Value += findgold.Value
			end
		end
1 Like

Tysm. This worked well. I was having a lot of trouble with this

1 Like

Tysm it worked though I was forced to only choose one as the solution so I am sorry.