Why is my script to change the height values if they are on a certain team roblox?

We looked at his game place and it turns out that the team was changing from a local script instead of a server script.

We ended up creating a script that changes the player’s team through a server script:

local gui = script.Parent
local player = script.Parent.Parent.Parent


for _, child in pairs(script.Parent:GetChildren())do
	local index = child.Name:find("Selection")
	
	--if the child is a team selection button:
	if index then
        --change team on button click: 
		local teamName = child.Name:sub(1, index-1)
		print(teamName)
		child.MouseButton1Click:connect(function()
			gui.Enabled = false
			player.Team = game:GetService("Teams"):FindFirstChild(teamName)
		end)
	end
end

image